Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.8% → 96.4%
Time: 30.3s
Alternatives: 17
Speedup: 1.9×

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 17 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: 75.8% 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.4% accurate, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 2: 71.7% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)\right)\\ t_1 := \cos M \cdot e^{M \cdot \left(n - M\right) - n}\\ \mathbf{if}\;\ell \leq -3 \cdot 10^{-76}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -1.45 \cdot 10^{-172}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-187}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -6.6 \cdot 10^{-295}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 1.5:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (+ -1.0 (- 1.0 (* l (cos (fma (* n 0.5) K (- M)))))))
        (t_1 (* (cos M) (exp (- (* M (- n M)) n)))))
   (if (<= l -3e-76)
     t_1
     (if (<= l -1.45e-172)
       t_0
       (if (<= l -1e-187)
         t_1
         (if (<= l -6.6e-295)
           t_0
           (if (<= l 1.5) t_1 (* (cos M) (exp (- l))))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = -1.0 + (1.0 - (l * cos(fma((n * 0.5), K, -M))));
	double t_1 = cos(M) * exp(((M * (n - M)) - n));
	double tmp;
	if (l <= -3e-76) {
		tmp = t_1;
	} else if (l <= -1.45e-172) {
		tmp = t_0;
	} else if (l <= -1e-187) {
		tmp = t_1;
	} else if (l <= -6.6e-295) {
		tmp = t_0;
	} else if (l <= 1.5) {
		tmp = t_1;
	} else {
		tmp = cos(M) * exp(-l);
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = Float64(-1.0 + Float64(1.0 - Float64(l * cos(fma(Float64(n * 0.5), K, Float64(-M))))))
	t_1 = Float64(cos(M) * exp(Float64(Float64(M * Float64(n - M)) - n)))
	tmp = 0.0
	if (l <= -3e-76)
		tmp = t_1;
	elseif (l <= -1.45e-172)
		tmp = t_0;
	elseif (l <= -1e-187)
		tmp = t_1;
	elseif (l <= -6.6e-295)
		tmp = t_0;
	elseif (l <= 1.5)
		tmp = t_1;
	else
		tmp = Float64(cos(M) * exp(Float64(-l)));
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(-1.0 + N[(1.0 - N[(l * N[Cos[N[(N[(n * 0.5), $MachinePrecision] * K + (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(M * N[(n - M), $MachinePrecision]), $MachinePrecision] - n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3e-76], t$95$1, If[LessEqual[l, -1.45e-172], t$95$0, If[LessEqual[l, -1e-187], t$95$1, If[LessEqual[l, -6.6e-295], t$95$0, If[LessEqual[l, 1.5], t$95$1, N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)\right)\\
t_1 := \cos M \cdot e^{M \cdot \left(n - M\right) - n}\\
\mathbf{if}\;\ell \leq -3 \cdot 10^{-76}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -1.45 \cdot 10^{-172}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -1 \cdot 10^{-187}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -6.6 \cdot 10^{-295}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 1.5:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.00000000000000024e-76 or -1.44999999999999999e-172 < l < -1e-187 or -6.5999999999999997e-295 < l < 1.5

    1. Initial program 78.8%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 95.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-neg95.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. Simplified95.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. Step-by-step derivation
      1. sub-neg95.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out74.7%

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

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

      \[\leadsto \cos M \cdot \color{blue}{e^{-\left(n + -1 \cdot \left(M \cdot \left(n - M\right)\right)\right)}} \]
    15. Step-by-step derivation
      1. neg-sub062.6%

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

        \[\leadsto \cos M \cdot e^{0 - \color{blue}{\left(-1 \cdot \left(M \cdot \left(n - M\right)\right) + n\right)}} \]
      3. associate--r+62.6%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(0 - -1 \cdot \left(M \cdot \left(n - M\right)\right)\right) - n}} \]
      4. neg-sub062.6%

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

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{\left(-M \cdot \left(n - M\right)\right)}\right) - n} \]
      6. remove-double-neg62.6%

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

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

    if -3.00000000000000024e-76 < l < -1.44999999999999999e-172 or -1e-187 < l < -6.5999999999999997e-295

    1. Initial program 92.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 l around inf 13.9%

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

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right) + \color{blue}{\left(-1 \cdot \ell\right) \cdot \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
      2. neg-mul-113.9%

        \[\leadsto \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right) + \color{blue}{\left(-\ell\right)} \cdot \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right) \]
      3. distribute-rgt1-in13.9%

        \[\leadsto \color{blue}{\left(\left(-\ell\right) + 1\right) \cdot \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
      4. fma-neg13.9%

        \[\leadsto \left(\left(-\ell\right) + 1\right) \cdot \cos \color{blue}{\left(\mathsf{fma}\left(0.5, K \cdot \left(m + n\right), -M\right)\right)} \]
    8. Simplified13.9%

      \[\leadsto \color{blue}{\left(\left(-\ell\right) + 1\right) \cdot \cos \left(\mathsf{fma}\left(0.5, K \cdot \left(m + n\right), -M\right)\right)} \]
    9. Taylor expanded in m around 0 14.3%

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) \cdot \left(1 - \ell\right)} \]
    10. Taylor expanded in l around inf 5.6%

      \[\leadsto \color{blue}{-1 \cdot \left(\ell \cdot \cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)} \]
    11. Step-by-step derivation
      1. associate-*r*5.6%

        \[\leadsto \color{blue}{\left(-1 \cdot \ell\right) \cdot \cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)} \]
      2. mul-1-neg5.6%

        \[\leadsto \color{blue}{\left(-\ell\right)} \cdot \cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) \]
      3. *-commutative5.6%

        \[\leadsto \left(-\ell\right) \cdot \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
      4. associate-*r*5.6%

        \[\leadsto \left(-\ell\right) \cdot \cos \left(\color{blue}{\left(0.5 \cdot n\right) \cdot K} - M\right) \]
      5. *-commutative5.6%

        \[\leadsto \left(-\ell\right) \cdot \cos \left(\color{blue}{\left(n \cdot 0.5\right)} \cdot K - M\right) \]
    12. Simplified5.6%

      \[\leadsto \color{blue}{\left(-\ell\right) \cdot \cos \left(\left(n \cdot 0.5\right) \cdot K - M\right)} \]
    13. Step-by-step derivation
      1. expm1-log1p-u5.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(-\ell\right) \cdot \cos \left(\left(n \cdot 0.5\right) \cdot K - M\right)\right)\right)} \]
      2. expm1-undefine80.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-\ell\right) \cdot \cos \left(\left(n \cdot 0.5\right) \cdot K - M\right)\right)} - 1} \]
      3. *-commutative80.6%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\cos \left(\left(n \cdot 0.5\right) \cdot K - M\right) \cdot \left(-\ell\right)}\right)} - 1 \]
      4. fma-neg80.6%

        \[\leadsto e^{\mathsf{log1p}\left(\cos \color{blue}{\left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)} \cdot \left(-\ell\right)\right)} - 1 \]
      5. *-commutative80.6%

        \[\leadsto e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(\color{blue}{0.5 \cdot n}, K, -M\right)\right) \cdot \left(-\ell\right)\right)} - 1 \]
    14. Applied egg-rr80.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)} - 1} \]
    15. Step-by-step derivation
      1. sub-neg80.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)} + \left(-1\right)} \]
      2. metadata-eval80.6%

        \[\leadsto e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)} + \color{blue}{-1} \]
      3. +-commutative80.6%

        \[\leadsto \color{blue}{-1 + e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)}} \]
      4. log1p-undefine80.6%

        \[\leadsto -1 + e^{\color{blue}{\log \left(1 + \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)}} \]
      5. rem-exp-log80.6%

        \[\leadsto -1 + \color{blue}{\left(1 + \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)} \]
      6. *-commutative80.6%

        \[\leadsto -1 + \left(1 + \color{blue}{\left(-\ell\right) \cdot \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right)}\right) \]
      7. distribute-lft-neg-in80.6%

        \[\leadsto -1 + \left(1 + \color{blue}{\left(-\ell \cdot \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right)\right)}\right) \]
      8. unsub-neg80.6%

        \[\leadsto -1 + \color{blue}{\left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right)\right)} \]
    16. Simplified80.6%

      \[\leadsto \color{blue}{-1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right)\right)} \]

    if 1.5 < l

    1. Initial program 82.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 l around inf 79.2%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3 \cdot 10^{-76}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(n - M\right) - n}\\ \mathbf{elif}\;\ell \leq -1.45 \cdot 10^{-172}:\\ \;\;\;\;-1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-187}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(n - M\right) - n}\\ \mathbf{elif}\;\ell \leq -6.6 \cdot 10^{-295}:\\ \;\;\;\;-1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.5:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(n - M\right) - n}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 85.1% accurate, 1.8× speedup?

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

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

\mathbf{elif}\;m \leq -2.8 \cdot 10^{+88}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(n - M\right) - n}\\

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

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


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

    1. Initial program 75.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. Step-by-step derivation
      1. sub-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out96.6%

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

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

    if -7.50000000000000033e162 < m < -2.79999999999999989e88

    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 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. Step-by-step derivation
      1. sub-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out63.1%

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

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

      \[\leadsto \cos M \cdot \color{blue}{e^{-\left(n + -1 \cdot \left(M \cdot \left(n - M\right)\right)\right)}} \]
    15. Step-by-step derivation
      1. neg-sub081.7%

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

        \[\leadsto \cos M \cdot e^{0 - \color{blue}{\left(-1 \cdot \left(M \cdot \left(n - M\right)\right) + n\right)}} \]
      3. associate--r+81.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(0 - -1 \cdot \left(M \cdot \left(n - M\right)\right)\right) - n}} \]
      4. neg-sub081.7%

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

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{\left(-M \cdot \left(n - M\right)\right)}\right) - n} \]
      6. remove-double-neg81.7%

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

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

    if -2.79999999999999989e88 < m < -4.00000000000000018e48

    1. Initial program 91.7%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. 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. Step-by-step derivation
      1. sub-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out91.8%

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

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

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

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

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

    if -4.00000000000000018e48 < m

    1. Initial program 82.8%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. 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 0 75.4%

      \[\leadsto \cos M \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)} \]
    7. Step-by-step derivation
      1. +-commutative75.4%

        \[\leadsto \cos M \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. unpow275.4%

        \[\leadsto \cos M \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-out79.5%

        \[\leadsto \cos M \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. *-commutative79.5%

        \[\leadsto \cos M \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. *-commutative79.5%

        \[\leadsto \cos M \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)} \]
    8. Simplified79.5%

      \[\leadsto \cos M \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)} \]
    9. Taylor expanded in l around inf 80.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -7.5 \cdot 10^{+162}:\\ \;\;\;\;\cos M \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(\left(M - m \cdot 0.5\right) - n\right) - n}\\ \mathbf{elif}\;m \leq -2.8 \cdot 10^{+88}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(n - M\right) - n}\\ \mathbf{elif}\;m \leq -4 \cdot 10^{+48}:\\ \;\;\;\;\cos M \cdot e^{\left(-n\right) - 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(n \cdot 0.5 - M\right) \cdot \left(\left(M - n \cdot 0.5\right) - m\right) - \ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 70.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{\left(-n\right) - 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)}\\ \mathbf{if}\;\ell \leq -5.4 \cdot 10^{-136}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -6.8 \cdot 10^{-279}:\\ \;\;\;\;-1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.5:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos M) (exp (- (- n) (* 0.5 (* m (+ n (* m 0.5)))))))))
   (if (<= l -5.4e-136)
     t_0
     (if (<= l -6.8e-279)
       (+ -1.0 (- 1.0 (* l (cos (fma (* n 0.5) K (- M))))))
       (if (<= l 1.5) t_0 (* (cos M) (exp (- l))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp((-n - (0.5 * (m * (n + (m * 0.5))))));
	double tmp;
	if (l <= -5.4e-136) {
		tmp = t_0;
	} else if (l <= -6.8e-279) {
		tmp = -1.0 + (1.0 - (l * cos(fma((n * 0.5), K, -M))));
	} else if (l <= 1.5) {
		tmp = t_0;
	} else {
		tmp = cos(M) * exp(-l);
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) * exp(Float64(Float64(-n) - Float64(0.5 * Float64(m * Float64(n + Float64(m * 0.5)))))))
	tmp = 0.0
	if (l <= -5.4e-136)
		tmp = t_0;
	elseif (l <= -6.8e-279)
		tmp = Float64(-1.0 + Float64(1.0 - Float64(l * cos(fma(Float64(n * 0.5), K, Float64(-M))))));
	elseif (l <= 1.5)
		tmp = t_0;
	else
		tmp = Float64(cos(M) * exp(Float64(-l)));
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] * N[Exp[N[((-n) - N[(0.5 * N[(m * N[(n + N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.4e-136], t$95$0, If[LessEqual[l, -6.8e-279], N[(-1.0 + N[(1.0 - N[(l * N[Cos[N[(N[(n * 0.5), $MachinePrecision] * K + (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.5], t$95$0, N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -6.8 \cdot 10^{-279}:\\
\;\;\;\;-1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 1.5:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.3999999999999997e-136 or -6.8000000000000003e-279 < l < 1.5

    1. Initial program 80.4%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 95.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-neg95.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. Simplified95.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. Step-by-step derivation
      1. sub-neg95.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out74.3%

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

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

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

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

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

    if -5.3999999999999997e-136 < l < -6.8000000000000003e-279

    1. Initial program 91.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 l around inf 12.6%

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

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right) + \color{blue}{\left(-1 \cdot \ell\right) \cdot \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
      2. neg-mul-112.6%

        \[\leadsto \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right) + \color{blue}{\left(-\ell\right)} \cdot \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right) \]
      3. distribute-rgt1-in12.6%

        \[\leadsto \color{blue}{\left(\left(-\ell\right) + 1\right) \cdot \cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
      4. fma-neg12.6%

        \[\leadsto \left(\left(-\ell\right) + 1\right) \cdot \cos \color{blue}{\left(\mathsf{fma}\left(0.5, K \cdot \left(m + n\right), -M\right)\right)} \]
    8. Simplified12.6%

      \[\leadsto \color{blue}{\left(\left(-\ell\right) + 1\right) \cdot \cos \left(\mathsf{fma}\left(0.5, K \cdot \left(m + n\right), -M\right)\right)} \]
    9. Taylor expanded in m around 0 13.3%

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) \cdot \left(1 - \ell\right)} \]
    10. Taylor expanded in l around inf 5.6%

      \[\leadsto \color{blue}{-1 \cdot \left(\ell \cdot \cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)} \]
    11. Step-by-step derivation
      1. associate-*r*5.6%

        \[\leadsto \color{blue}{\left(-1 \cdot \ell\right) \cdot \cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)} \]
      2. mul-1-neg5.6%

        \[\leadsto \color{blue}{\left(-\ell\right)} \cdot \cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) \]
      3. *-commutative5.6%

        \[\leadsto \left(-\ell\right) \cdot \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
      4. associate-*r*5.6%

        \[\leadsto \left(-\ell\right) \cdot \cos \left(\color{blue}{\left(0.5 \cdot n\right) \cdot K} - M\right) \]
      5. *-commutative5.6%

        \[\leadsto \left(-\ell\right) \cdot \cos \left(\color{blue}{\left(n \cdot 0.5\right)} \cdot K - M\right) \]
    12. Simplified5.6%

      \[\leadsto \color{blue}{\left(-\ell\right) \cdot \cos \left(\left(n \cdot 0.5\right) \cdot K - M\right)} \]
    13. Step-by-step derivation
      1. expm1-log1p-u5.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(-\ell\right) \cdot \cos \left(\left(n \cdot 0.5\right) \cdot K - M\right)\right)\right)} \]
      2. expm1-undefine82.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(-\ell\right) \cdot \cos \left(\left(n \cdot 0.5\right) \cdot K - M\right)\right)} - 1} \]
      3. *-commutative82.9%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\cos \left(\left(n \cdot 0.5\right) \cdot K - M\right) \cdot \left(-\ell\right)}\right)} - 1 \]
      4. fma-neg82.9%

        \[\leadsto e^{\mathsf{log1p}\left(\cos \color{blue}{\left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)} \cdot \left(-\ell\right)\right)} - 1 \]
      5. *-commutative82.9%

        \[\leadsto e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(\color{blue}{0.5 \cdot n}, K, -M\right)\right) \cdot \left(-\ell\right)\right)} - 1 \]
    14. Applied egg-rr82.9%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)} - 1} \]
    15. Step-by-step derivation
      1. sub-neg82.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)} + \left(-1\right)} \]
      2. metadata-eval82.9%

        \[\leadsto e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)} + \color{blue}{-1} \]
      3. +-commutative82.9%

        \[\leadsto \color{blue}{-1 + e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)}} \]
      4. log1p-undefine82.9%

        \[\leadsto -1 + e^{\color{blue}{\log \left(1 + \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)}} \]
      5. rem-exp-log82.9%

        \[\leadsto -1 + \color{blue}{\left(1 + \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right) \cdot \left(-\ell\right)\right)} \]
      6. *-commutative82.9%

        \[\leadsto -1 + \left(1 + \color{blue}{\left(-\ell\right) \cdot \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right)}\right) \]
      7. distribute-lft-neg-in82.9%

        \[\leadsto -1 + \left(1 + \color{blue}{\left(-\ell \cdot \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right)\right)}\right) \]
      8. unsub-neg82.9%

        \[\leadsto -1 + \color{blue}{\left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right)\right)} \]
    16. Simplified82.9%

      \[\leadsto \color{blue}{-1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(0.5 \cdot n, K, -M\right)\right)\right)} \]

    if 1.5 < l

    1. Initial program 82.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 l around inf 79.2%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.4 \cdot 10^{-136}:\\ \;\;\;\;\cos M \cdot e^{\left(-n\right) - 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)}\\ \mathbf{elif}\;\ell \leq -6.8 \cdot 10^{-279}:\\ \;\;\;\;-1 + \left(1 - \ell \cdot \cos \left(\mathsf{fma}\left(n \cdot 0.5, K, -M\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.5:\\ \;\;\;\;\cos M \cdot e^{\left(-n\right) - 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 75.3% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 82.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 95.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-neg95.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. Simplified95.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. Step-by-step derivation
      1. sub-neg95.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out67.3%

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

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

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

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

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

    if -1.40000000000000011e-103 < l < 720

    1. Initial program 82.8%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 95.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-neg95.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. Simplified95.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. Step-by-step derivation
      1. sub-neg95.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 720 < l

    1. Initial program 81.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 l around inf 81.7%

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

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

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

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

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

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

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

Alternative 6: 88.7% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 82.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. Step-by-step derivation
      1. sub-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

    if -11200 < m

    1. Initial program 82.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.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-neg95.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. Simplified95.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 0 75.9%

      \[\leadsto \cos M \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)} \]
    7. Step-by-step derivation
      1. +-commutative75.9%

        \[\leadsto \cos M \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. unpow275.9%

        \[\leadsto \cos M \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-out80.0%

        \[\leadsto \cos M \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. *-commutative80.0%

        \[\leadsto \cos M \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. *-commutative80.0%

        \[\leadsto \cos M \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)} \]
    8. Simplified80.0%

      \[\leadsto \cos M \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)} \]
    9. Taylor expanded in l around inf 80.8%

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

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

Alternative 7: 96.3% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(m + n\right) \cdot 0.5\\ \cos M \cdot e^{\left(t\_0 - M\right) \cdot \left(M - t\_0\right) + \left(\left(m - n\right) - \ell\right)} \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (+ m n) 0.5)))
   (* (cos M) (exp (+ (* (- t_0 M) (- M t_0)) (- (- m n) l))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = (m + n) * 0.5;
	return cos(M) * exp((((t_0 - M) * (M - t_0)) + ((m - n) - 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
    real(8) :: t_0
    t_0 = (m + n) * 0.5d0
    code = cos(m_1) * exp((((t_0 - m_1) * (m_1 - t_0)) + ((m - n) - l)))
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = (m + n) * 0.5;
	return Math.cos(M) * Math.exp((((t_0 - M) * (M - t_0)) + ((m - n) - l)));
}
def code(K, m, n, M, l):
	t_0 = (m + n) * 0.5
	return math.cos(M) * math.exp((((t_0 - M) * (M - t_0)) + ((m - n) - l)))
function code(K, m, n, M, l)
	t_0 = Float64(Float64(m + n) * 0.5)
	return Float64(cos(M) * exp(Float64(Float64(Float64(t_0 - M) * Float64(M - t_0)) + Float64(Float64(m - n) - l))))
end
function tmp = code(K, m, n, M, l)
	t_0 = (m + n) * 0.5;
	tmp = cos(M) * exp((((t_0 - M) * (M - t_0)) + ((m - n) - l)));
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision]}, N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(N[(t$95$0 - M), $MachinePrecision] * N[(M - t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[(m - n), $MachinePrecision] - l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5\\
\cos M \cdot e^{\left(t\_0 - M\right) \cdot \left(M - t\_0\right) + \left(\left(m - n\right) - \ell\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 82.4%

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

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

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

    \[\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. Step-by-step derivation
    1. sub-neg96.3%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\left(\left(m + n\right) \cdot 0.5 - M\right) \cdot \left(M - \left(m + n\right) \cdot 0.5\right) + \left(\left(m - n\right) - \ell\right)} \]
  11. Add Preprocessing

Alternative 8: 45.8% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.75 \cdot 10^{-177}:\\
\;\;\;\;e^{-0.5 \cdot \left(m \cdot n\right)}\\

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

\mathbf{elif}\;n \leq 3.3 \cdot 10^{-43}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if n < -1.7500000000000001e-177

    1. Initial program 84.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 m around 0 62.0%

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

        \[\leadsto \cos M \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. unpow267.2%

        \[\leadsto \cos M \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-out75.2%

        \[\leadsto \cos M \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. *-commutative75.2%

        \[\leadsto \cos M \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. *-commutative75.2%

        \[\leadsto \cos M \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. Simplified66.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 m around inf 31.5%

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{m \cdot \left(M - n \cdot 0.5\right)} \]
    10. Step-by-step derivation
      1. cos-neg95.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)} \]
    11. Simplified38.6%

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

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

    if -1.7500000000000001e-177 < n < -3.7999999999999998e-288

    1. Initial program 84.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 m around 0 68.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. +-commutative69.2%

        \[\leadsto \cos M \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. unpow269.2%

        \[\leadsto \cos M \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-out73.3%

        \[\leadsto \cos M \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. *-commutative73.3%

        \[\leadsto \cos M \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. *-commutative73.3%

        \[\leadsto \cos M \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. Simplified72.3%

      \[\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 m around inf 33.4%

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{m \cdot \left(M - n \cdot 0.5\right)} \]
    10. Step-by-step derivation
      1. cos-neg96.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)} \]
    11. Simplified34.4%

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

    if -3.7999999999999998e-288 < n < 3.30000000000000016e-43

    1. Initial program 86.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 l around inf 43.9%

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

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

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

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

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

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

    if 3.30000000000000016e-43 < n

    1. Initial program 75.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 97.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-neg97.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. Simplified97.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. Step-by-step derivation
      1. sub-neg97.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out74.3%

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

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

      \[\leadsto \cos M \cdot \color{blue}{e^{-\left(n + -1 \cdot \left(M \cdot \left(n - M\right)\right)\right)}} \]
    15. Step-by-step derivation
      1. neg-sub079.9%

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

        \[\leadsto \cos M \cdot e^{0 - \color{blue}{\left(-1 \cdot \left(M \cdot \left(n - M\right)\right) + n\right)}} \]
      3. associate--r+79.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(0 - -1 \cdot \left(M \cdot \left(n - M\right)\right)\right) - n}} \]
      4. neg-sub079.9%

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

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

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

      \[\leadsto \cos M \cdot \color{blue}{e^{M \cdot \left(n - M\right) - n}} \]
    17. Taylor expanded in M around 0 56.3%

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

Alternative 9: 76.1% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 84.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 95.3%

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

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

      \[\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. Step-by-step derivation
      1. sub-neg95.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out75.2%

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

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

    if 2.8999999999999998e47 < n

    1. Initial program 75.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. Step-by-step derivation
      1. sub-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 47.2% accurate, 1.9× speedup?

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

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

\mathbf{elif}\;\ell \leq -1.05 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)\\

\mathbf{elif}\;\ell \leq 1.5:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.15e234 or -1.04999999999999997e154 < l < 1.5

    1. Initial program 81.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 58.7%

      \[\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. +-commutative67.3%

        \[\leadsto \cos M \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. unpow267.3%

        \[\leadsto \cos M \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-out73.4%

        \[\leadsto \cos M \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. *-commutative73.4%

        \[\leadsto \cos M \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. *-commutative73.4%

        \[\leadsto \cos M \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. Simplified62.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 m around inf 38.9%

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

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

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

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

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

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

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

    if -1.15e234 < l < -1.04999999999999997e154

    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 n around inf 46.9%

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(\left(m \cdot K\right) \cdot 0.5 - M\right)} \]
    7. Taylor expanded in m around 0 2.7%

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

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

        \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(-M\right)\right)} \]
      3. *-commutative2.7%

        \[\leadsto \cos M + -0.5 \cdot \left(\color{blue}{\left(m \cdot K\right)} \cdot \sin \left(-M\right)\right) \]
      4. sin-neg2.7%

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

      \[\leadsto \color{blue}{\cos M + -0.5 \cdot \left(\left(m \cdot K\right) \cdot \left(-\sin M\right)\right)} \]
    10. Taylor expanded in m around inf 30.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)} \]

    if 1.5 < l

    1. Initial program 82.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 l around inf 79.2%

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

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

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

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

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

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

Alternative 11: 48.1% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;\ell \leq 450:\\
\;\;\;\;\cos M \cdot e^{M \cdot m}\\

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


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

    1. Initial program 85.4%

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

      \[\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. +-commutative68.6%

        \[\leadsto \cos M \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. unpow268.6%

        \[\leadsto \cos M \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-out72.5%

        \[\leadsto \cos M \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. *-commutative72.5%

        \[\leadsto \cos M \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. *-commutative72.5%

        \[\leadsto \cos M \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. Simplified65.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 m around inf 37.2%

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{m \cdot \left(M - n \cdot 0.5\right)} \]
    10. Step-by-step derivation
      1. cos-neg95.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)} \]
    11. Simplified41.1%

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

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

    if -1.1500000000000001e-222 < l < 450

    1. Initial program 79.3%

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

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

        \[\leadsto \cos M \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. unpow266.2%

        \[\leadsto \cos M \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-out73.9%

        \[\leadsto \cos M \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. *-commutative73.9%

        \[\leadsto \cos M \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. *-commutative73.9%

        \[\leadsto \cos M \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.9%

      \[\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 m around inf 37.7%

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

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

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

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

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

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

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

    if 450 < l

    1. Initial program 81.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 l around inf 81.7%

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

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

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

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

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

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

Alternative 12: 69.7% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 82.4%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 95.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-neg95.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. Simplified95.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. Step-by-step derivation
      1. sub-neg95.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out76.1%

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

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

      \[\leadsto \cos M \cdot \color{blue}{e^{-\left(n + -1 \cdot \left(M \cdot \left(n - M\right)\right)\right)}} \]
    15. Step-by-step derivation
      1. neg-sub062.1%

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

        \[\leadsto \cos M \cdot e^{0 - \color{blue}{\left(-1 \cdot \left(M \cdot \left(n - M\right)\right) + n\right)}} \]
      3. associate--r+62.1%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(0 - -1 \cdot \left(M \cdot \left(n - M\right)\right)\right) - n}} \]
      4. neg-sub062.1%

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

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{\left(-M \cdot \left(n - M\right)\right)}\right) - n} \]
      6. remove-double-neg62.1%

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

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

    if 1.5 < l

    1. Initial program 82.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 l around inf 79.2%

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

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

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

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

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

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

Alternative 13: 52.4% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 9.6 \cdot 10^{-18}:\\
\;\;\;\;\cos M \cdot e^{M \cdot n - n}\\

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


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

    1. Initial program 83.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 95.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-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)} \]
    5. Simplified95.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. Step-by-step derivation
      1. sub-neg95.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \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) + n\right)} \]
      3. distribute-rgt-out75.9%

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

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

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

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

        \[\leadsto \cos M \cdot e^{0 - \color{blue}{\left(-1 \cdot \left(M \cdot \left(n - M\right)\right) + n\right)}} \]
      3. associate--r+62.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(0 - -1 \cdot \left(M \cdot \left(n - M\right)\right)\right) - n}} \]
      4. neg-sub062.0%

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

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{\left(-M \cdot \left(n - M\right)\right)}\right) - n} \]
      6. remove-double-neg62.0%

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

      \[\leadsto \cos M \cdot \color{blue}{e^{M \cdot \left(n - M\right) - n}} \]
    17. Taylor expanded in M around 0 37.2%

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

    if 9.59999999999999976e-18 < l

    1. Initial program 80.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 l around inf 73.4%

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

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

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

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

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

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

Alternative 14: 35.5% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)\\ t_1 := e^{-0.5 \cdot \left(m \cdot n\right)}\\ \mathbf{if}\;m \leq -6.8 \cdot 10^{-127}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;m \leq -1 \cdot 10^{-240}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;m \leq -9 \cdot 10^{-247}:\\ \;\;\;\;1\\ \mathbf{elif}\;m \leq 1.8 \cdot 10^{-235}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* 0.5 (* K (* m (sin M))))) (t_1 (exp (* -0.5 (* m n)))))
   (if (<= m -6.8e-127)
     t_1
     (if (<= m -1e-240)
       t_0
       (if (<= m -9e-247) 1.0 (if (<= m 1.8e-235) t_0 t_1))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = 0.5 * (K * (m * sin(M)));
	double t_1 = exp((-0.5 * (m * n)));
	double tmp;
	if (m <= -6.8e-127) {
		tmp = t_1;
	} else if (m <= -1e-240) {
		tmp = t_0;
	} else if (m <= -9e-247) {
		tmp = 1.0;
	} else if (m <= 1.8e-235) {
		tmp = 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 = 0.5d0 * (k * (m * sin(m_1)))
    t_1 = exp(((-0.5d0) * (m * n)))
    if (m <= (-6.8d-127)) then
        tmp = t_1
    else if (m <= (-1d-240)) then
        tmp = t_0
    else if (m <= (-9d-247)) then
        tmp = 1.0d0
    else if (m <= 1.8d-235) then
        tmp = 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 = 0.5 * (K * (m * Math.sin(M)));
	double t_1 = Math.exp((-0.5 * (m * n)));
	double tmp;
	if (m <= -6.8e-127) {
		tmp = t_1;
	} else if (m <= -1e-240) {
		tmp = t_0;
	} else if (m <= -9e-247) {
		tmp = 1.0;
	} else if (m <= 1.8e-235) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = 0.5 * (K * (m * math.sin(M)))
	t_1 = math.exp((-0.5 * (m * n)))
	tmp = 0
	if m <= -6.8e-127:
		tmp = t_1
	elif m <= -1e-240:
		tmp = t_0
	elif m <= -9e-247:
		tmp = 1.0
	elif m <= 1.8e-235:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(0.5 * Float64(K * Float64(m * sin(M))))
	t_1 = exp(Float64(-0.5 * Float64(m * n)))
	tmp = 0.0
	if (m <= -6.8e-127)
		tmp = t_1;
	elseif (m <= -1e-240)
		tmp = t_0;
	elseif (m <= -9e-247)
		tmp = 1.0;
	elseif (m <= 1.8e-235)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = 0.5 * (K * (m * sin(M)));
	t_1 = exp((-0.5 * (m * n)));
	tmp = 0.0;
	if (m <= -6.8e-127)
		tmp = t_1;
	elseif (m <= -1e-240)
		tmp = t_0;
	elseif (m <= -9e-247)
		tmp = 1.0;
	elseif (m <= 1.8e-235)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(0.5 * N[(K * N[(m * N[Sin[M], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(-0.5 * N[(m * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[m, -6.8e-127], t$95$1, If[LessEqual[m, -1e-240], t$95$0, If[LessEqual[m, -9e-247], 1.0, If[LessEqual[m, 1.8e-235], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)\\
t_1 := e^{-0.5 \cdot \left(m \cdot n\right)}\\
\mathbf{if}\;m \leq -6.8 \cdot 10^{-127}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;m \leq -1 \cdot 10^{-240}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;m \leq -9 \cdot 10^{-247}:\\
\;\;\;\;1\\

\mathbf{elif}\;m \leq 1.8 \cdot 10^{-235}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < -6.7999999999999997e-127 or 1.79999999999999999e-235 < m

    1. Initial program 79.2%

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

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

        \[\leadsto \cos M \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. unpow262.7%

        \[\leadsto \cos M \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-out69.9%

        \[\leadsto \cos M \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. *-commutative69.9%

        \[\leadsto \cos M \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. *-commutative69.9%

        \[\leadsto \cos M \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. Simplified58.0%

      \[\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 m around inf 33.8%

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{m \cdot \left(M - n \cdot 0.5\right)} \]
    10. Step-by-step derivation
      1. cos-neg95.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)} \]
    11. Simplified41.0%

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

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

    if -6.7999999999999997e-127 < m < -9.9999999999999997e-241 or -9.0000000000000005e-247 < m < 1.79999999999999999e-235

    1. Initial program 95.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 n around inf 54.5%

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

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

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

        \[\leadsto \cos \left(\color{blue}{\left(m \cdot K\right)} \cdot 0.5 - M\right) \]
    6. Simplified15.4%

      \[\leadsto \color{blue}{\cos \left(\left(m \cdot K\right) \cdot 0.5 - M\right)} \]
    7. Taylor expanded in m around 0 15.4%

      \[\leadsto \color{blue}{\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
    8. Step-by-step derivation
      1. cos-neg15.4%

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

        \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(-M\right)\right)} \]
      3. *-commutative15.4%

        \[\leadsto \cos M + -0.5 \cdot \left(\color{blue}{\left(m \cdot K\right)} \cdot \sin \left(-M\right)\right) \]
      4. sin-neg15.4%

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

      \[\leadsto \color{blue}{\cos M + -0.5 \cdot \left(\left(m \cdot K\right) \cdot \left(-\sin M\right)\right)} \]
    10. Taylor expanded in m around inf 55.1%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)} \]

    if -9.9999999999999997e-241 < m < -9.0000000000000005e-247

    1. Initial program 100.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 inf 100.0%

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

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

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

        \[\leadsto \cos \left(\color{blue}{\left(m \cdot K\right)} \cdot 0.5 - M\right) \]
    6. Simplified100.0%

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

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

        \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(m \cdot K\right)}\right) \]
    9. Simplified100.0%

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(m \cdot K\right)\right)} \]
    10. Taylor expanded in m around 0 100.0%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 15: 30.6% accurate, 4.0× speedup?

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

\\
e^{-0.5 \cdot \left(m \cdot n\right)}
\end{array}
Derivation
  1. Initial program 82.4%

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

    \[\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. +-commutative69.3%

      \[\leadsto \cos M \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. unpow269.3%

      \[\leadsto \cos M \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-out75.2%

      \[\leadsto \cos M \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. *-commutative75.2%

      \[\leadsto \cos M \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. *-commutative75.2%

      \[\leadsto \cos M \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. Simplified65.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 m around inf 33.3%

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

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

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

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

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

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

    \[\leadsto \color{blue}{e^{-0.5 \cdot \left(m \cdot n\right)}} \]
  13. Add Preprocessing

Alternative 16: 6.9% 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 82.4%

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

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

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

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

      \[\leadsto \cos \left(\color{blue}{\left(m \cdot K\right)} \cdot 0.5 - M\right) \]
  6. Simplified9.2%

    \[\leadsto \color{blue}{\cos \left(\left(m \cdot K\right) \cdot 0.5 - M\right)} \]
  7. Taylor expanded in m around 0 9.8%

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  8. Step-by-step derivation
    1. cos-neg9.8%

      \[\leadsto \color{blue}{\cos M} \]
  9. Simplified9.8%

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

Alternative 17: 6.9% accurate, 425.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (K m n M l) :precision binary64 1.0)
double code(double K, double m, double n, double M, double l) {
	return 1.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 = 1.0d0
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
def code(K, m, n, M, l):
	return 1.0
function code(K, m, n, M, l)
	return 1.0
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0;
end
code[K_, m_, n_, M_, l_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 82.4%

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

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

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

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

      \[\leadsto \cos \left(\color{blue}{\left(m \cdot K\right)} \cdot 0.5 - M\right) \]
  6. Simplified9.2%

    \[\leadsto \color{blue}{\cos \left(\left(m \cdot K\right) \cdot 0.5 - M\right)} \]
  7. Taylor expanded in M around 0 9.2%

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

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(m \cdot K\right)}\right) \]
  9. Simplified9.2%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(m \cdot K\right)\right)} \]
  10. Taylor expanded in m around 0 9.8%

    \[\leadsto \color{blue}{1} \]
  11. Add Preprocessing

Reproduce

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