Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 96.7%
Time: 14.4s
Alternatives: 9
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 76.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.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 71.7% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\left(\left|m - n\right| - \ell\right) + m \cdot \left(m \cdot -0.25\right)}\\
\mathbf{if}\;n \leq 5.2 \cdot 10^{-178}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 7.8 \cdot 10^{-18}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\

\mathbf{elif}\;n \leq 0.88:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < 5.19999999999999997e-178 or 7.8000000000000001e-18 < n < 0.880000000000000004

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\left(\left|m - n\right| - \ell\right) - 0.25 \cdot \color{blue}{\left(m \cdot m\right)}} \]
      3. cancel-sign-sub-inv65.1%

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

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

        \[\leadsto e^{\left(\left|m - n\right| - \ell\right) + \color{blue}{\left(m \cdot m\right) \cdot -0.25}} \]
      6. associate-*l*65.1%

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

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

    if 5.19999999999999997e-178 < n < 7.8000000000000001e-18

    1. Initial program 90.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. *-commutative90.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in59.2%

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

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

    if 0.880000000000000004 < n

    1. Initial program 65.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 79.6% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq -7.8 \cdot 10^{-255}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;m \leq 7.8 \cdot 10^{-153}:\\
\;\;\;\;\cos M \cdot t_1\\

\mathbf{elif}\;m \leq 55:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -52 < m < -7.8000000000000001e-255 or 7.8000000000000004e-153 < m < 55

    1. Initial program 83.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. *-commutative83.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in59.1%

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

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

    if -7.8000000000000001e-255 < m < 7.8000000000000004e-153

    1. Initial program 85.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. *-commutative85.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot \left(m \cdot m\right)}} \]
    10. Taylor expanded in m around 0 12.8%

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

        \[\leadsto -0.25 \cdot \left(\color{blue}{\left(m \cdot m\right)} \cdot \cos M\right) + \cos M \]
      2. associate-*r*12.8%

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left(m \cdot m\right)\right) \cdot \cos M} + \cos M \]
      3. metadata-eval12.8%

        \[\leadsto \left(\color{blue}{\left(-0.25\right)} \cdot \left(m \cdot m\right)\right) \cdot \cos M + \cos M \]
      4. distribute-lft-neg-in12.8%

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left(m \cdot m\right)\right)} \cdot \cos M + \cos M \]
      5. *-commutative12.8%

        \[\leadsto \left(-\color{blue}{\left(m \cdot m\right) \cdot 0.25}\right) \cdot \cos M + \cos M \]
      6. associate-*r*12.8%

        \[\leadsto \left(-\color{blue}{m \cdot \left(m \cdot 0.25\right)}\right) \cdot \cos M + \cos M \]
      7. distribute-lft1-in12.8%

        \[\leadsto \color{blue}{\left(\left(-m \cdot \left(m \cdot 0.25\right)\right) + 1\right) \cdot \cos M} \]
      8. distribute-rgt-neg-in12.8%

        \[\leadsto \left(\color{blue}{m \cdot \left(-m \cdot 0.25\right)} + 1\right) \cdot \cos M \]
      9. fma-def12.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(m, -m \cdot 0.25, 1\right)} \cdot \cos M \]
      10. distribute-rgt-neg-in12.8%

        \[\leadsto \mathsf{fma}\left(m, \color{blue}{m \cdot \left(-0.25\right)}, 1\right) \cdot \cos M \]
      11. metadata-eval12.8%

        \[\leadsto \mathsf{fma}\left(m, m \cdot \color{blue}{-0.25}, 1\right) \cdot \cos M \]
    12. Simplified12.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(m, m \cdot -0.25, 1\right) \cdot \cos M} \]
    13. Taylor expanded in m around inf 75.7%

      \[\leadsto \color{blue}{-0.25 \cdot \left({m}^{2} \cdot \cos M\right)} \]
    14. Step-by-step derivation
      1. associate-*r*75.7%

        \[\leadsto \color{blue}{\left(-0.25 \cdot {m}^{2}\right) \cdot \cos M} \]
      2. unpow275.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -52:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -7.8 \cdot 10^{-255}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;m \leq 7.8 \cdot 10^{-153}:\\ \;\;\;\;\cos M \cdot \left(-0.25 \cdot \left(m \cdot m\right)\right)\\ \mathbf{elif}\;m \leq 55:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \end{array} \]

Alternative 4: 67.3% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq -7.8 \cdot 10^{-255}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\

\mathbf{elif}\;m \leq 6.2 \cdot 10^{-182}:\\
\;\;\;\;\cos M \cdot t_0\\

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


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

    1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -52 < m < -7.8000000000000001e-255

    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. *-commutative79.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in55.4%

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

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

    if -7.8000000000000001e-255 < m < 6.20000000000000016e-182

    1. Initial program 83.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. *-commutative83.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot \left(m \cdot m\right)}} \]
    10. Taylor expanded in m around 0 11.9%

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

        \[\leadsto -0.25 \cdot \left(\color{blue}{\left(m \cdot m\right)} \cdot \cos M\right) + \cos M \]
      2. associate-*r*11.9%

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left(m \cdot m\right)\right) \cdot \cos M} + \cos M \]
      3. metadata-eval11.9%

        \[\leadsto \left(\color{blue}{\left(-0.25\right)} \cdot \left(m \cdot m\right)\right) \cdot \cos M + \cos M \]
      4. distribute-lft-neg-in11.9%

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left(m \cdot m\right)\right)} \cdot \cos M + \cos M \]
      5. *-commutative11.9%

        \[\leadsto \left(-\color{blue}{\left(m \cdot m\right) \cdot 0.25}\right) \cdot \cos M + \cos M \]
      6. associate-*r*11.9%

        \[\leadsto \left(-\color{blue}{m \cdot \left(m \cdot 0.25\right)}\right) \cdot \cos M + \cos M \]
      7. distribute-lft1-in11.9%

        \[\leadsto \color{blue}{\left(\left(-m \cdot \left(m \cdot 0.25\right)\right) + 1\right) \cdot \cos M} \]
      8. distribute-rgt-neg-in11.9%

        \[\leadsto \left(\color{blue}{m \cdot \left(-m \cdot 0.25\right)} + 1\right) \cdot \cos M \]
      9. fma-def11.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(m, -m \cdot 0.25, 1\right)} \cdot \cos M \]
      10. distribute-rgt-neg-in11.9%

        \[\leadsto \mathsf{fma}\left(m, \color{blue}{m \cdot \left(-0.25\right)}, 1\right) \cdot \cos M \]
      11. metadata-eval11.9%

        \[\leadsto \mathsf{fma}\left(m, m \cdot \color{blue}{-0.25}, 1\right) \cdot \cos M \]
    12. Simplified11.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(m, m \cdot -0.25, 1\right) \cdot \cos M} \]
    13. Taylor expanded in m around inf 78.1%

      \[\leadsto \color{blue}{-0.25 \cdot \left({m}^{2} \cdot \cos M\right)} \]
    14. Step-by-step derivation
      1. associate-*r*78.1%

        \[\leadsto \color{blue}{\left(-0.25 \cdot {m}^{2}\right) \cdot \cos M} \]
      2. unpow278.1%

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

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

    if 6.20000000000000016e-182 < m

    1. Initial program 76.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -52:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -7.8 \cdot 10^{-255}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;m \leq 6.2 \cdot 10^{-182}:\\ \;\;\;\;\cos M \cdot \left(-0.25 \cdot \left(m \cdot m\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]

Alternative 5: 76.8% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 84.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left(m - n\right)} - \ell\right) + \left(-M\right) \cdot M} \cdot \cos M \]
    11. Applied egg-rr74.2%

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

    if 4.99999999999999976e67 < n

    1. Initial program 61.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. *-commutative61.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 70.4% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 81.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. *-commutative81.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in96.9%

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

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

    if -62 < M < 26.5

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 44.5% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -3.2 \cdot 10^{-158} \lor \neg \left(m \leq 6.2 \cdot 10^{-182}\right):\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -3.19999999999999996e-158 or 6.20000000000000016e-182 < 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. *-commutative78.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.19999999999999996e-158 < m < 6.20000000000000016e-182

    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. *-commutative83.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot \left(m \cdot m\right)}} \]
    10. Taylor expanded in m around 0 10.8%

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

        \[\leadsto -0.25 \cdot \left(\color{blue}{\left(m \cdot m\right)} \cdot \cos M\right) + \cos M \]
      2. associate-*r*10.8%

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left(m \cdot m\right)\right) \cdot \cos M} + \cos M \]
      3. metadata-eval10.8%

        \[\leadsto \left(\color{blue}{\left(-0.25\right)} \cdot \left(m \cdot m\right)\right) \cdot \cos M + \cos M \]
      4. distribute-lft-neg-in10.8%

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left(m \cdot m\right)\right)} \cdot \cos M + \cos M \]
      5. *-commutative10.8%

        \[\leadsto \left(-\color{blue}{\left(m \cdot m\right) \cdot 0.25}\right) \cdot \cos M + \cos M \]
      6. associate-*r*10.8%

        \[\leadsto \left(-\color{blue}{m \cdot \left(m \cdot 0.25\right)}\right) \cdot \cos M + \cos M \]
      7. distribute-lft1-in10.8%

        \[\leadsto \color{blue}{\left(\left(-m \cdot \left(m \cdot 0.25\right)\right) + 1\right) \cdot \cos M} \]
      8. distribute-rgt-neg-in10.8%

        \[\leadsto \left(\color{blue}{m \cdot \left(-m \cdot 0.25\right)} + 1\right) \cdot \cos M \]
      9. fma-def10.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(m, -m \cdot 0.25, 1\right)} \cdot \cos M \]
      10. distribute-rgt-neg-in10.8%

        \[\leadsto \mathsf{fma}\left(m, \color{blue}{m \cdot \left(-0.25\right)}, 1\right) \cdot \cos M \]
      11. metadata-eval10.8%

        \[\leadsto \mathsf{fma}\left(m, m \cdot \color{blue}{-0.25}, 1\right) \cdot \cos M \]
    12. Simplified10.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(m, m \cdot -0.25, 1\right) \cdot \cos M} \]
    13. Taylor expanded in m around inf 77.8%

      \[\leadsto \color{blue}{-0.25 \cdot \left({m}^{2} \cdot \cos M\right)} \]
    14. Step-by-step derivation
      1. associate-*r*77.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -3.2 \cdot 10^{-158} \lor \neg \left(m \leq 6.2 \cdot 10^{-182}\right):\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot \left(-0.25 \cdot \left(m \cdot m\right)\right)\\ \end{array} \]

Alternative 8: 22.9% accurate, 3.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -3.6 \cdot 10^{-134}:\\
\;\;\;\;\cos M\\

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


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

    1. Initial program 79.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. *-commutative79.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot \left(m \cdot m\right)}} \]
    10. Taylor expanded in m around 0 6.6%

      \[\leadsto \color{blue}{\cos M} \]

    if -3.5999999999999999e-134 < m

    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. *-commutative80.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot \left(m \cdot m\right)}} \]
    10. Taylor expanded in m around 0 8.3%

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

        \[\leadsto -0.25 \cdot \left(\color{blue}{\left(m \cdot m\right)} \cdot \cos M\right) + \cos M \]
      2. associate-*r*8.3%

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left(m \cdot m\right)\right) \cdot \cos M} + \cos M \]
      3. metadata-eval8.3%

        \[\leadsto \left(\color{blue}{\left(-0.25\right)} \cdot \left(m \cdot m\right)\right) \cdot \cos M + \cos M \]
      4. distribute-lft-neg-in8.3%

        \[\leadsto \color{blue}{\left(-0.25 \cdot \left(m \cdot m\right)\right)} \cdot \cos M + \cos M \]
      5. *-commutative8.3%

        \[\leadsto \left(-\color{blue}{\left(m \cdot m\right) \cdot 0.25}\right) \cdot \cos M + \cos M \]
      6. associate-*r*8.3%

        \[\leadsto \left(-\color{blue}{m \cdot \left(m \cdot 0.25\right)}\right) \cdot \cos M + \cos M \]
      7. distribute-lft1-in8.3%

        \[\leadsto \color{blue}{\left(\left(-m \cdot \left(m \cdot 0.25\right)\right) + 1\right) \cdot \cos M} \]
      8. distribute-rgt-neg-in8.3%

        \[\leadsto \left(\color{blue}{m \cdot \left(-m \cdot 0.25\right)} + 1\right) \cdot \cos M \]
      9. fma-def8.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(m, -m \cdot 0.25, 1\right)} \cdot \cos M \]
      10. distribute-rgt-neg-in8.3%

        \[\leadsto \mathsf{fma}\left(m, \color{blue}{m \cdot \left(-0.25\right)}, 1\right) \cdot \cos M \]
      11. metadata-eval8.3%

        \[\leadsto \mathsf{fma}\left(m, m \cdot \color{blue}{-0.25}, 1\right) \cdot \cos M \]
    12. Simplified8.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(m, m \cdot -0.25, 1\right) \cdot \cos M} \]
    13. Taylor expanded in m around inf 32.3%

      \[\leadsto \color{blue}{-0.25 \cdot \left({m}^{2} \cdot \cos M\right)} \]
    14. Step-by-step derivation
      1. associate-*r*32.3%

        \[\leadsto \color{blue}{\left(-0.25 \cdot {m}^{2}\right) \cdot \cos M} \]
      2. unpow232.3%

        \[\leadsto \left(-0.25 \cdot \color{blue}{\left(m \cdot m\right)}\right) \cdot \cos M \]
    15. Simplified32.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -3.6 \cdot 10^{-134}:\\ \;\;\;\;\cos M\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot \left(-0.25 \cdot \left(m \cdot m\right)\right)\\ \end{array} \]

Alternative 9: 7.3% 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.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. *-commutative79.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot \left(m \cdot m\right)}} \]
  10. Taylor expanded in m around 0 7.9%

    \[\leadsto \color{blue}{\cos M} \]
  11. Final simplification7.9%

    \[\leadsto \cos M \]

Reproduce

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