Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.5% → 96.5%
Time: 21.9s
Alternatives: 16
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 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.5% accurate, 1.0× speedup?

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

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

Alternative 1: 96.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{\left(\left|n - m\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 (- n m)) 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((n - m)) - 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((n - m)) - 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((n - m)) - 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((n - m)) - 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(n - m)) - 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((n - m)) - 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[(n - m), $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|n - m\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 74.5%

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

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

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

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

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

Alternative 2: 68.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := \cos M \cdot e^{-{M}^{2}}\\ \mathbf{if}\;M \leq -1.56 \cdot 10^{-6}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq -1.75 \cdot 10^{-154}:\\ \;\;\;\;\cos M \cdot t\_0\\ \mathbf{elif}\;M \leq -1.05 \cdot 10^{-296}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \mathbf{elif}\;M \leq 5.2 \cdot 10^{-160}:\\ \;\;\;\;\left(\left(0.5 \cdot K\right) \cdot \left(n \cdot \sin M\right)\right) \cdot t\_0\\ \mathbf{elif}\;M \leq 9 \cdot 10^{-57}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot t\_0\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- l))) (t_1 (* (cos M) (exp (- (pow M 2.0))))))
   (if (<= M -1.56e-6)
     t_1
     (if (<= M -1.75e-154)
       (* (cos M) t_0)
       (if (<= M -1.05e-296)
         (* (cos M) (exp (* n (- M (* m 0.5)))))
         (if (<= M 5.2e-160)
           (* (* (* 0.5 K) (* n (sin M))) t_0)
           (if (<= M 9e-57)
             t_0
             (if (<= M 27.0) (* 0.5 (* K (* m (* (sin M) t_0)))) t_1))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(-l);
	double t_1 = cos(M) * exp(-pow(M, 2.0));
	double tmp;
	if (M <= -1.56e-6) {
		tmp = t_1;
	} else if (M <= -1.75e-154) {
		tmp = cos(M) * t_0;
	} else if (M <= -1.05e-296) {
		tmp = cos(M) * exp((n * (M - (m * 0.5))));
	} else if (M <= 5.2e-160) {
		tmp = ((0.5 * K) * (n * sin(M))) * t_0;
	} else if (M <= 9e-57) {
		tmp = t_0;
	} else if (M <= 27.0) {
		tmp = 0.5 * (K * (m * (sin(M) * t_0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = cos(m_1) * exp(-(m_1 ** 2.0d0))
    if (m_1 <= (-1.56d-6)) then
        tmp = t_1
    else if (m_1 <= (-1.75d-154)) then
        tmp = cos(m_1) * t_0
    else if (m_1 <= (-1.05d-296)) then
        tmp = cos(m_1) * exp((n * (m_1 - (m * 0.5d0))))
    else if (m_1 <= 5.2d-160) then
        tmp = ((0.5d0 * k) * (n * sin(m_1))) * t_0
    else if (m_1 <= 9d-57) then
        tmp = t_0
    else if (m_1 <= 27.0d0) then
        tmp = 0.5d0 * (k * (m * (sin(m_1) * t_0)))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(-l);
	double t_1 = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
	double tmp;
	if (M <= -1.56e-6) {
		tmp = t_1;
	} else if (M <= -1.75e-154) {
		tmp = Math.cos(M) * t_0;
	} else if (M <= -1.05e-296) {
		tmp = Math.cos(M) * Math.exp((n * (M - (m * 0.5))));
	} else if (M <= 5.2e-160) {
		tmp = ((0.5 * K) * (n * Math.sin(M))) * t_0;
	} else if (M <= 9e-57) {
		tmp = t_0;
	} else if (M <= 27.0) {
		tmp = 0.5 * (K * (m * (Math.sin(M) * t_0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp(-l)
	t_1 = math.cos(M) * math.exp(-math.pow(M, 2.0))
	tmp = 0
	if M <= -1.56e-6:
		tmp = t_1
	elif M <= -1.75e-154:
		tmp = math.cos(M) * t_0
	elif M <= -1.05e-296:
		tmp = math.cos(M) * math.exp((n * (M - (m * 0.5))))
	elif M <= 5.2e-160:
		tmp = ((0.5 * K) * (n * math.sin(M))) * t_0
	elif M <= 9e-57:
		tmp = t_0
	elif M <= 27.0:
		tmp = 0.5 * (K * (m * (math.sin(M) * t_0)))
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(-l))
	t_1 = Float64(cos(M) * exp(Float64(-(M ^ 2.0))))
	tmp = 0.0
	if (M <= -1.56e-6)
		tmp = t_1;
	elseif (M <= -1.75e-154)
		tmp = Float64(cos(M) * t_0);
	elseif (M <= -1.05e-296)
		tmp = Float64(cos(M) * exp(Float64(n * Float64(M - Float64(m * 0.5)))));
	elseif (M <= 5.2e-160)
		tmp = Float64(Float64(Float64(0.5 * K) * Float64(n * sin(M))) * t_0);
	elseif (M <= 9e-57)
		tmp = t_0;
	elseif (M <= 27.0)
		tmp = Float64(0.5 * Float64(K * Float64(m * Float64(sin(M) * t_0))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(-l);
	t_1 = cos(M) * exp(-(M ^ 2.0));
	tmp = 0.0;
	if (M <= -1.56e-6)
		tmp = t_1;
	elseif (M <= -1.75e-154)
		tmp = cos(M) * t_0;
	elseif (M <= -1.05e-296)
		tmp = cos(M) * exp((n * (M - (m * 0.5))));
	elseif (M <= 5.2e-160)
		tmp = ((0.5 * K) * (n * sin(M))) * t_0;
	elseif (M <= 9e-57)
		tmp = t_0;
	elseif (M <= 27.0)
		tmp = 0.5 * (K * (m * (sin(M) * t_0)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -1.56e-6], t$95$1, If[LessEqual[M, -1.75e-154], N[(N[Cos[M], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[M, -1.05e-296], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(n * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 5.2e-160], N[(N[(N[(0.5 * K), $MachinePrecision] * N[(n * N[Sin[M], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[M, 9e-57], t$95$0, If[LessEqual[M, 27.0], N[(0.5 * N[(K * N[(m * N[(N[Sin[M], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := \cos M \cdot e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -1.56 \cdot 10^{-6}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;M \leq -1.75 \cdot 10^{-154}:\\
\;\;\;\;\cos M \cdot t\_0\\

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

\mathbf{elif}\;M \leq 5.2 \cdot 10^{-160}:\\
\;\;\;\;\left(\left(0.5 \cdot K\right) \cdot \left(n \cdot \sin M\right)\right) \cdot t\_0\\

\mathbf{elif}\;M \leq 9 \cdot 10^{-57}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 27:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot t\_0\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


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

    1. Initial program 73.1%

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

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

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

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

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

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

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

    if -1.5600000000000001e-6 < M < -1.75e-154

    1. Initial program 62.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. Add Preprocessing
    3. Taylor expanded in K around 0 96.6%

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

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

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

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

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

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

    if -1.75e-154 < M < -1.05e-296

    1. Initial program 68.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. Add Preprocessing
    3. Taylor expanded in n around 0 46.6%

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

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

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

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

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

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

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

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

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

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

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

    if -1.05e-296 < M < 5.20000000000000007e-160

    1. Initial program 81.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. Add Preprocessing
    3. Taylor expanded in K around 0 93.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.5 \cdot \left(K \cdot \left(n \cdot \sin M\right)\right)\right)} \cdot e^{-\ell} \]
    10. Step-by-step derivation
      1. associate-*r*63.6%

        \[\leadsto \color{blue}{\left(\left(0.5 \cdot K\right) \cdot \left(n \cdot \sin M\right)\right)} \cdot e^{-\ell} \]
    11. Simplified63.6%

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

    if 5.20000000000000007e-160 < M < 8.99999999999999945e-57

    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. Add Preprocessing
    3. Taylor expanded in K around 0 96.1%

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

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

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

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

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

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

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

    if 8.99999999999999945e-57 < M < 27

    1. Initial program 83.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. Add Preprocessing
    3. Taylor expanded in K around 0 83.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{-\ell} \cdot \sin M\right)\right)\right)} \]
  3. Recombined 6 regimes into one program.
  4. Final simplification77.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -1.56 \cdot 10^{-6}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq -1.75 \cdot 10^{-154}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq -1.05 \cdot 10^{-296}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \mathbf{elif}\;M \leq 5.2 \cdot 10^{-160}:\\ \;\;\;\;\left(\left(0.5 \cdot K\right) \cdot \left(n \cdot \sin M\right)\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 9 \cdot 10^{-57}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot e^{-\ell}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.2% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ t_1 := e^{-\ell}\\ t_2 := \cos M \cdot e^{-{M}^{2}}\\ \mathbf{if}\;M \leq -28.5:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;M \leq 1.5 \cdot 10^{-304}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 3.5 \cdot 10^{-227}:\\ \;\;\;\;\left(\left(0.5 \cdot K\right) \cdot \left(n \cdot \sin M\right)\right) \cdot t\_1\\ \mathbf{elif}\;M \leq 2.4 \cdot 10^{-68}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot t\_1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos M) (exp (* -0.25 (pow m 2.0)))))
        (t_1 (exp (- l)))
        (t_2 (* (cos M) (exp (- (pow M 2.0))))))
   (if (<= M -28.5)
     t_2
     (if (<= M 1.5e-304)
       t_0
       (if (<= M 3.5e-227)
         (* (* (* 0.5 K) (* n (sin M))) t_1)
         (if (<= M 2.4e-68)
           t_0
           (if (<= M 27.0) (* 0.5 (* K (* m (* (sin M) t_1)))) t_2)))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp((-0.25 * pow(m, 2.0)));
	double t_1 = exp(-l);
	double t_2 = cos(M) * exp(-pow(M, 2.0));
	double tmp;
	if (M <= -28.5) {
		tmp = t_2;
	} else if (M <= 1.5e-304) {
		tmp = t_0;
	} else if (M <= 3.5e-227) {
		tmp = ((0.5 * K) * (n * sin(M))) * t_1;
	} else if (M <= 2.4e-68) {
		tmp = t_0;
	} else if (M <= 27.0) {
		tmp = 0.5 * (K * (m * (sin(M) * t_1)));
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = cos(m_1) * exp(((-0.25d0) * (m ** 2.0d0)))
    t_1 = exp(-l)
    t_2 = cos(m_1) * exp(-(m_1 ** 2.0d0))
    if (m_1 <= (-28.5d0)) then
        tmp = t_2
    else if (m_1 <= 1.5d-304) then
        tmp = t_0
    else if (m_1 <= 3.5d-227) then
        tmp = ((0.5d0 * k) * (n * sin(m_1))) * t_1
    else if (m_1 <= 2.4d-68) then
        tmp = t_0
    else if (m_1 <= 27.0d0) then
        tmp = 0.5d0 * (k * (m * (sin(m_1) * t_1)))
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.cos(M) * Math.exp((-0.25 * Math.pow(m, 2.0)));
	double t_1 = Math.exp(-l);
	double t_2 = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
	double tmp;
	if (M <= -28.5) {
		tmp = t_2;
	} else if (M <= 1.5e-304) {
		tmp = t_0;
	} else if (M <= 3.5e-227) {
		tmp = ((0.5 * K) * (n * Math.sin(M))) * t_1;
	} else if (M <= 2.4e-68) {
		tmp = t_0;
	} else if (M <= 27.0) {
		tmp = 0.5 * (K * (m * (Math.sin(M) * t_1)));
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(M) * math.exp((-0.25 * math.pow(m, 2.0)))
	t_1 = math.exp(-l)
	t_2 = math.cos(M) * math.exp(-math.pow(M, 2.0))
	tmp = 0
	if M <= -28.5:
		tmp = t_2
	elif M <= 1.5e-304:
		tmp = t_0
	elif M <= 3.5e-227:
		tmp = ((0.5 * K) * (n * math.sin(M))) * t_1
	elif M <= 2.4e-68:
		tmp = t_0
	elif M <= 27.0:
		tmp = 0.5 * (K * (m * (math.sin(M) * t_1)))
	else:
		tmp = t_2
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) * exp(Float64(-0.25 * (m ^ 2.0))))
	t_1 = exp(Float64(-l))
	t_2 = Float64(cos(M) * exp(Float64(-(M ^ 2.0))))
	tmp = 0.0
	if (M <= -28.5)
		tmp = t_2;
	elseif (M <= 1.5e-304)
		tmp = t_0;
	elseif (M <= 3.5e-227)
		tmp = Float64(Float64(Float64(0.5 * K) * Float64(n * sin(M))) * t_1);
	elseif (M <= 2.4e-68)
		tmp = t_0;
	elseif (M <= 27.0)
		tmp = Float64(0.5 * Float64(K * Float64(m * Float64(sin(M) * t_1))));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = cos(M) * exp((-0.25 * (m ^ 2.0)));
	t_1 = exp(-l);
	t_2 = cos(M) * exp(-(M ^ 2.0));
	tmp = 0.0;
	if (M <= -28.5)
		tmp = t_2;
	elseif (M <= 1.5e-304)
		tmp = t_0;
	elseif (M <= 3.5e-227)
		tmp = ((0.5 * K) * (n * sin(M))) * t_1;
	elseif (M <= 2.4e-68)
		tmp = t_0;
	elseif (M <= 27.0)
		tmp = 0.5 * (K * (m * (sin(M) * t_1)));
	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[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -28.5], t$95$2, If[LessEqual[M, 1.5e-304], t$95$0, If[LessEqual[M, 3.5e-227], N[(N[(N[(0.5 * K), $MachinePrecision] * N[(n * N[Sin[M], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[M, 2.4e-68], t$95$0, If[LessEqual[M, 27.0], N[(0.5 * N[(K * N[(m * N[(N[Sin[M], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;M \leq 1.5 \cdot 10^{-304}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 3.5 \cdot 10^{-227}:\\
\;\;\;\;\left(\left(0.5 \cdot K\right) \cdot \left(n \cdot \sin M\right)\right) \cdot t\_1\\

\mathbf{elif}\;M \leq 2.4 \cdot 10^{-68}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 27:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot t\_1\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


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

    1. Initial program 73.5%

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

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

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

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

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

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

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

    if -28.5 < M < 1.5000000000000001e-304 or 3.5000000000000001e-227 < M < 2.39999999999999991e-68

    1. Initial program 71.5%

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

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

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

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

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

    if 1.5000000000000001e-304 < M < 3.5000000000000001e-227

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.5 \cdot \left(K \cdot \left(n \cdot \sin M\right)\right)\right)} \cdot e^{-\ell} \]
    10. Step-by-step derivation
      1. associate-*r*70.4%

        \[\leadsto \color{blue}{\left(\left(0.5 \cdot K\right) \cdot \left(n \cdot \sin M\right)\right)} \cdot e^{-\ell} \]
    11. Simplified70.4%

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

    if 2.39999999999999991e-68 < M < 27

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{-\ell} \cdot \sin M\right)\right)\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification85.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -28.5:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq 1.5 \cdot 10^{-304}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;M \leq 3.5 \cdot 10^{-227}:\\ \;\;\;\;\left(\left(0.5 \cdot K\right) \cdot \left(n \cdot \sin M\right)\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 2.4 \cdot 10^{-68}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot e^{-\ell}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 86.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := M - n \cdot 0.5\\
\mathbf{if}\;m \leq -29.5:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\

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


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

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

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

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

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

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

    if -29.5 < m

    1. Initial program 76.3%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 87.0% accurate, 1.3× speedup?

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

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

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


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

    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. Add Preprocessing
    3. Taylor expanded in n around 0 64.1%

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

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

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

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

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

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

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

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

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

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

    if 19 < n

    1. Initial program 73.3%

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

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

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

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

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

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

Alternative 6: 68.1% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 74.3%

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

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

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

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

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

    if 8.19999999999999965e-308 < n < 19

    1. Initial program 76.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. Add Preprocessing
    3. Taylor expanded in m around 0 57.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 19 < n

    1. Initial program 73.3%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 8.2 \cdot 10^{-308}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;n \leq 19:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) + \left(\left|n - m\right| - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 73.6% accurate, 1.3× speedup?

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

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

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


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

    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. Add Preprocessing
    3. Taylor expanded in n around 0 64.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 19 < n

    1. Initial program 73.3%

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

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

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

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

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

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

Alternative 8: 64.9% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;m \leq -2.55 \cdot 10^{-306}:\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

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


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

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

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

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

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

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

    if -29.5 < m < -2.54999999999999986e-306

    1. Initial program 75.5%

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

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

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

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

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

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

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

    if -2.54999999999999986e-306 < m

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

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

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

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

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

Alternative 9: 53.8% accurate, 1.9× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot e^{-\ell}\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < 1.10000000000000001e-242

    1. Initial program 76.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. Add Preprocessing
    3. Taylor expanded in m around 0 55.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.10000000000000001e-242 < l < 3.64999999999999991

    1. Initial program 69.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. Add Preprocessing
    3. Taylor expanded in n around 0 47.1%

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

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

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

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

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

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

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

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

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

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

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

    if 3.64999999999999991 < l

    1. Initial program 73.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 1.1 \cdot 10^{-242}:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\ \mathbf{elif}\;\ell \leq 3.65:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot e^{-\ell}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 53.8% accurate, 1.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < 1.9000000000000001e-242

    1. Initial program 76.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. Add Preprocessing
    3. Taylor expanded in m around 0 55.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.9000000000000001e-242 < l < 3.7000000000000002

    1. Initial program 69.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. Add Preprocessing
    3. Taylor expanded in n around 0 47.1%

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

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

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

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

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

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

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

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

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

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

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

    if 3.7000000000000002 < l

    1. Initial program 73.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 1.9 \cdot 10^{-242}:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\ \mathbf{elif}\;\ell \leq 3.7:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 53.9% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 74.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. Add Preprocessing
    3. Taylor expanded in m around 0 52.3%

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

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

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

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

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

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

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

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

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

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

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

    if 1.60000000000000006e-9 < l

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

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

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

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

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

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

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

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

Alternative 12: 36.0% accurate, 2.1× speedup?

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

\\
\cos M \cdot e^{-\ell}
\end{array}
Derivation
  1. Initial program 74.5%

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  9. Add Preprocessing

Alternative 13: 35.7% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 74.5%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{e^{-\ell}} \]
  10. Add Preprocessing

Alternative 14: 7.1% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 74.5%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos M} \]
  10. Add Preprocessing

Alternative 15: 6.4% accurate, 38.6× speedup?

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

\\
1 + 0.5 \cdot \left(\left(m + n\right) \cdot \left(M \cdot K\right)\right)
\end{array}
Derivation
  1. Initial program 74.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right) + M \cdot \sin \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)} \]
  7. Step-by-step derivation
    1. *-commutative4.9%

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\right) + M \cdot \sin \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right) \]
    2. *-commutative4.9%

      \[\leadsto \cos \left(0.5 \cdot \left(\left(m + n\right) \cdot K\right)\right) + M \cdot \sin \left(0.5 \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\right) \]
  8. Simplified4.9%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(\left(m + n\right) \cdot K\right)\right) + M \cdot \sin \left(0.5 \cdot \left(\left(m + n\right) \cdot K\right)\right)} \]
  9. Taylor expanded in K around 0 5.0%

    \[\leadsto \color{blue}{1 + 0.5 \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\right)} \]
  10. Step-by-step derivation
    1. associate-*r*5.4%

      \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(\left(K \cdot M\right) \cdot \left(m + n\right)\right)} \]
  11. Simplified5.4%

    \[\leadsto \color{blue}{1 + 0.5 \cdot \left(\left(K \cdot M\right) \cdot \left(m + n\right)\right)} \]
  12. Final simplification5.4%

    \[\leadsto 1 + 0.5 \cdot \left(\left(m + n\right) \cdot \left(M \cdot K\right)\right) \]
  13. Add Preprocessing

Alternative 16: 6.3% accurate, 38.6× speedup?

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

\\
1 + 0.5 \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\right)
\end{array}
Derivation
  1. Initial program 74.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right) + M \cdot \sin \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)} \]
  7. Step-by-step derivation
    1. *-commutative4.9%

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\right) + M \cdot \sin \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right) \]
    2. *-commutative4.9%

      \[\leadsto \cos \left(0.5 \cdot \left(\left(m + n\right) \cdot K\right)\right) + M \cdot \sin \left(0.5 \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\right) \]
  8. Simplified4.9%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(\left(m + n\right) \cdot K\right)\right) + M \cdot \sin \left(0.5 \cdot \left(\left(m + n\right) \cdot K\right)\right)} \]
  9. Taylor expanded in K around 0 5.0%

    \[\leadsto \color{blue}{1 + 0.5 \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\right)} \]
  10. Add Preprocessing

Reproduce

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