Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.4% → 96.7%
Time: 22.7s
Alternatives: 17
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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

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

Alternative 1: 96.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\ \mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_0 \leq 2 \cdot 10^{-98}:\\ \;\;\;\;t\_0 \cdot \log \left(e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, -M\right)\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \cos M\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- (- (fabs (- m n)) l) (pow (- (/ (+ m n) 2.0) M) 2.0)))))
   (if (<= (* (cos (- (/ (* K (+ m n)) 2.0) M)) t_0) 2e-98)
     (* t_0 (log (exp (cos (fma K (* (+ m n) 0.5) (- M))))))
     (* t_0 (cos M)))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(((fabs((m - n)) - l) - pow((((m + n) / 2.0) - M), 2.0)));
	double tmp;
	if ((cos((((K * (m + n)) / 2.0) - M)) * t_0) <= 2e-98) {
		tmp = t_0 * log(exp(cos(fma(K, ((m + n) * 0.5), -M))));
	} else {
		tmp = t_0 * cos(M);
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))
	tmp = 0.0
	if (Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * t_0) <= 2e-98)
		tmp = Float64(t_0 * log(exp(cos(fma(K, Float64(Float64(m + n) * 0.5), Float64(-M))))));
	else
		tmp = Float64(t_0 * cos(M));
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], 2e-98], N[(t$95$0 * N[Log[N[Exp[N[Cos[N[(K * N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision] + (-M)), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Cos[M], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
\mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_0 \leq 2 \cdot 10^{-98}:\\
\;\;\;\;t\_0 \cdot \log \left(e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, -M\right)\right)}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \cos M\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 1.99999999999999988e-98

    1. Initial program 98.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. Step-by-step derivation
      1. add-log-exp98.2%

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

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

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

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

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

      \[\leadsto \color{blue}{\log \left(e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, -M\right)\right)}\right)} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]

    if 1.99999999999999988e-98 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

    1. Initial program 28.6%

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. Simplified96.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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \leq 2 \cdot 10^{-98}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \log \left(e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, -M\right)\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos M\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(m + n\right) \cdot 0.5\\ t_1 := \sqrt[3]{t\_0 - M}\\ t_2 := \left|m - n\right| - \ell\\ t_3 := e^{t\_2 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\ t_4 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ \mathbf{if}\;t\_4 \cdot t\_3 \leq 0:\\ \;\;\;\;t\_4 \cdot e^{{t\_1}^{2} \cdot \left(t\_1 \cdot \left(M - t\_0\right)\right) + t\_2}\\ \mathbf{else}:\\ \;\;\;\;t\_3 \cdot \cos M\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (+ m n) 0.5))
        (t_1 (cbrt (- t_0 M)))
        (t_2 (- (fabs (- m n)) l))
        (t_3 (exp (- t_2 (pow (- (/ (+ m n) 2.0) M) 2.0))))
        (t_4 (cos (- (/ (* K (+ m n)) 2.0) M))))
   (if (<= (* t_4 t_3) 0.0)
     (* t_4 (exp (+ (* (pow t_1 2.0) (* t_1 (- M t_0))) t_2)))
     (* t_3 (cos M)))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = (m + n) * 0.5;
	double t_1 = cbrt((t_0 - M));
	double t_2 = fabs((m - n)) - l;
	double t_3 = exp((t_2 - pow((((m + n) / 2.0) - M), 2.0)));
	double t_4 = cos((((K * (m + n)) / 2.0) - M));
	double tmp;
	if ((t_4 * t_3) <= 0.0) {
		tmp = t_4 * exp(((pow(t_1, 2.0) * (t_1 * (M - t_0))) + t_2));
	} else {
		tmp = t_3 * cos(M);
	}
	return tmp;
}
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = (m + n) * 0.5;
	double t_1 = Math.cbrt((t_0 - M));
	double t_2 = Math.abs((m - n)) - l;
	double t_3 = Math.exp((t_2 - Math.pow((((m + n) / 2.0) - M), 2.0)));
	double t_4 = Math.cos((((K * (m + n)) / 2.0) - M));
	double tmp;
	if ((t_4 * t_3) <= 0.0) {
		tmp = t_4 * Math.exp(((Math.pow(t_1, 2.0) * (t_1 * (M - t_0))) + t_2));
	} else {
		tmp = t_3 * Math.cos(M);
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = Float64(Float64(m + n) * 0.5)
	t_1 = cbrt(Float64(t_0 - M))
	t_2 = Float64(abs(Float64(m - n)) - l)
	t_3 = exp(Float64(t_2 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))
	t_4 = cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M))
	tmp = 0.0
	if (Float64(t_4 * t_3) <= 0.0)
		tmp = Float64(t_4 * exp(Float64(Float64((t_1 ^ 2.0) * Float64(t_1 * Float64(M - t_0))) + t_2)));
	else
		tmp = Float64(t_3 * cos(M));
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(t$95$0 - M), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$2 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$3 = N[Exp[N[(t$95$2 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$4 * t$95$3), $MachinePrecision], 0.0], N[(t$95$4 * N[Exp[N[(N[(N[Power[t$95$1, 2.0], $MachinePrecision] * N[(t$95$1 * N[(M - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$3 * N[Cos[M], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5\\
t_1 := \sqrt[3]{t\_0 - M}\\
t_2 := \left|m - n\right| - \ell\\
t_3 := e^{t\_2 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
t_4 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
\mathbf{if}\;t\_4 \cdot t\_3 \leq 0:\\
\;\;\;\;t\_4 \cdot e^{{t\_1}^{2} \cdot \left(t\_1 \cdot \left(M - t\_0\right)\right) + t\_2}\\

\mathbf{else}:\\
\;\;\;\;t\_3 \cdot \cos M\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 0.0

    1. Initial program 98.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. Step-by-step derivation
      1. unpow298.2%

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

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

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

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

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

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

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

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

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

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

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

    if 0.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

    1. Initial program 29.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 96.5%

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

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

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

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

Alternative 3: 96.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\ t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ \mathbf{if}\;t\_2 \cdot t\_1 \leq -2 \cdot 10^{-64}:\\ \;\;\;\;t\_2 \cdot e^{t\_0 - {\left(\sqrt[3]{\left(m \cdot 0.5 - M\right) \cdot \left(m \cdot 0.5 + \left(n - M\right)\right)}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot \cos M\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (fabs (- m n)) l))
        (t_1 (exp (- t_0 (pow (- (/ (+ m n) 2.0) M) 2.0))))
        (t_2 (cos (- (/ (* K (+ m n)) 2.0) M))))
   (if (<= (* t_2 t_1) -2e-64)
     (*
      t_2
      (exp (- t_0 (pow (cbrt (* (- (* m 0.5) M) (+ (* m 0.5) (- n M)))) 3.0))))
     (* t_1 (cos M)))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n)) - l;
	double t_1 = exp((t_0 - pow((((m + n) / 2.0) - M), 2.0)));
	double t_2 = cos((((K * (m + n)) / 2.0) - M));
	double tmp;
	if ((t_2 * t_1) <= -2e-64) {
		tmp = t_2 * exp((t_0 - pow(cbrt((((m * 0.5) - M) * ((m * 0.5) + (n - M)))), 3.0)));
	} else {
		tmp = t_1 * cos(M);
	}
	return tmp;
}
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.abs((m - n)) - l;
	double t_1 = Math.exp((t_0 - Math.pow((((m + n) / 2.0) - M), 2.0)));
	double t_2 = Math.cos((((K * (m + n)) / 2.0) - M));
	double tmp;
	if ((t_2 * t_1) <= -2e-64) {
		tmp = t_2 * Math.exp((t_0 - Math.pow(Math.cbrt((((m * 0.5) - M) * ((m * 0.5) + (n - M)))), 3.0)));
	} else {
		tmp = t_1 * Math.cos(M);
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = Float64(abs(Float64(m - n)) - l)
	t_1 = exp(Float64(t_0 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))
	t_2 = cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M))
	tmp = 0.0
	if (Float64(t_2 * t_1) <= -2e-64)
		tmp = Float64(t_2 * exp(Float64(t_0 - (cbrt(Float64(Float64(Float64(m * 0.5) - M) * Float64(Float64(m * 0.5) + Float64(n - M)))) ^ 3.0))));
	else
		tmp = Float64(t_1 * cos(M));
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(t$95$0 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$2 * t$95$1), $MachinePrecision], -2e-64], N[(t$95$2 * N[Exp[N[(t$95$0 - N[Power[N[Power[N[(N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision] * N[(N[(m * 0.5), $MachinePrecision] + N[(n - M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[Cos[M], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|m - n\right| - \ell\\
t_1 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
\mathbf{if}\;t\_2 \cdot t\_1 \leq -2 \cdot 10^{-64}:\\
\;\;\;\;t\_2 \cdot e^{t\_0 - {\left(\sqrt[3]{\left(m \cdot 0.5 - M\right) \cdot \left(m \cdot 0.5 + \left(n - M\right)\right)}\right)}^{3}}\\

\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \cos M\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < -1.99999999999999993e-64

    1. Initial program 60.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.99999999999999993e-64 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

    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 K around 0 99.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-neg99.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. Simplified99.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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.8%

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

Alternative 4: 96.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\ t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ \mathbf{if}\;t\_2 \cdot t\_1 \leq -2 \cdot 10^{-64}:\\ \;\;\;\;t\_2 \cdot e^{\mathsf{fma}\left(m \cdot 0.5 - M, \left(M - n\right) - m \cdot 0.5, t\_0\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot \cos M\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (fabs (- m n)) l))
        (t_1 (exp (- t_0 (pow (- (/ (+ m n) 2.0) M) 2.0))))
        (t_2 (cos (- (/ (* K (+ m n)) 2.0) M))))
   (if (<= (* t_2 t_1) -2e-64)
     (* t_2 (exp (fma (- (* m 0.5) M) (- (- M n) (* m 0.5)) t_0)))
     (* t_1 (cos M)))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n)) - l;
	double t_1 = exp((t_0 - pow((((m + n) / 2.0) - M), 2.0)));
	double t_2 = cos((((K * (m + n)) / 2.0) - M));
	double tmp;
	if ((t_2 * t_1) <= -2e-64) {
		tmp = t_2 * exp(fma(((m * 0.5) - M), ((M - n) - (m * 0.5)), t_0));
	} else {
		tmp = t_1 * cos(M);
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = Float64(abs(Float64(m - n)) - l)
	t_1 = exp(Float64(t_0 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))
	t_2 = cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M))
	tmp = 0.0
	if (Float64(t_2 * t_1) <= -2e-64)
		tmp = Float64(t_2 * exp(fma(Float64(Float64(m * 0.5) - M), Float64(Float64(M - n) - Float64(m * 0.5)), t_0)));
	else
		tmp = Float64(t_1 * cos(M));
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(t$95$0 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$2 * t$95$1), $MachinePrecision], -2e-64], N[(t$95$2 * N[Exp[N[(N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - n), $MachinePrecision] - N[(m * 0.5), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[Cos[M], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|m - n\right| - \ell\\
t_1 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
\mathbf{if}\;t\_2 \cdot t\_1 \leq -2 \cdot 10^{-64}:\\
\;\;\;\;t\_2 \cdot e^{\mathsf{fma}\left(m \cdot 0.5 - M, \left(M - n\right) - m \cdot 0.5, t\_0\right)}\\

\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \cos M\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < -1.99999999999999993e-64

    1. Initial program 60.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 \cdot e^{\color{blue}{\mathsf{fma}\left(m \cdot 0.5 - M, -\left(\left(m \cdot 0.5 - M\right) + n\right), -\left(\ell - \left|m - n\right|\right)\right)}}\right) \]
      4. associate-+l-57.9%

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\left(1 \cdot e^{\mathsf{fma}\left(m \cdot 0.5 - M, -\left(m \cdot 0.5 - \left(M - n\right)\right), -\left(\ell - \left|m - n\right|\right)\right)}\right)} \]
    8. Step-by-step derivation
      1. *-lft-identity57.9%

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\mathsf{fma}\left(m \cdot 0.5 - M, -\color{blue}{\left(\left(n + \left(-M\right)\right) + 0.5 \cdot m\right)}, -\left(\ell - \left|m - n\right|\right)\right)} \]
      10. sub-neg57.9%

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

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

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

    if -1.99999999999999993e-64 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

    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 K around 0 99.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-neg99.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. Simplified99.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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.8%

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

Alternative 5: 96.7% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
t_1 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_0\\
\mathbf{if}\;t\_1 \leq 2 \cdot 10^{-98}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \cos M\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 1.99999999999999988e-98

    1. Initial program 98.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

    if 1.99999999999999988e-98 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

    1. Initial program 28.6%

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. Simplified96.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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.9%

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

Alternative 6: 96.6% accurate, 1.0× speedup?

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

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

Alternative 7: 71.4% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ \mathbf{if}\;m \leq -54:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq -1.15 \cdot 10^{-227} \lor \neg \left(m \leq 1.15 \cdot 10^{-248}\right) \land m \leq 9.5 \cdot 10^{-170}:\\ \;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{t\_0 + M \cdot \left(n - M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{t\_0 - 0.5 \cdot \left(n \cdot \left(m + n \cdot 0.5\right)\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (fabs (- m n)) l)))
   (if (<= m -54.0)
     (* (cos M) (exp (* -0.25 (pow m 2.0))))
     (if (or (<= m -1.15e-227) (and (not (<= m 1.15e-248)) (<= m 9.5e-170)))
       (* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (+ t_0 (* M (- n M)))))
       (* (cos M) (exp (- t_0 (* 0.5 (* n (+ m (* n 0.5)))))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n)) - l;
	double tmp;
	if (m <= -54.0) {
		tmp = cos(M) * exp((-0.25 * pow(m, 2.0)));
	} else if ((m <= -1.15e-227) || (!(m <= 1.15e-248) && (m <= 9.5e-170))) {
		tmp = cos((((K * (m + n)) / 2.0) - M)) * exp((t_0 + (M * (n - M))));
	} else {
		tmp = cos(M) * exp((t_0 - (0.5 * (n * (m + (n * 0.5))))));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: tmp
    t_0 = abs((m - n)) - l
    if (m <= (-54.0d0)) then
        tmp = cos(m_1) * exp(((-0.25d0) * (m ** 2.0d0)))
    else if ((m <= (-1.15d-227)) .or. (.not. (m <= 1.15d-248)) .and. (m <= 9.5d-170)) then
        tmp = cos((((k * (m + n)) / 2.0d0) - m_1)) * exp((t_0 + (m_1 * (n - m_1))))
    else
        tmp = cos(m_1) * exp((t_0 - (0.5d0 * (n * (m + (n * 0.5d0))))))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.abs((m - n)) - l;
	double tmp;
	if (m <= -54.0) {
		tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(m, 2.0)));
	} else if ((m <= -1.15e-227) || (!(m <= 1.15e-248) && (m <= 9.5e-170))) {
		tmp = Math.cos((((K * (m + n)) / 2.0) - M)) * Math.exp((t_0 + (M * (n - M))));
	} else {
		tmp = Math.cos(M) * Math.exp((t_0 - (0.5 * (n * (m + (n * 0.5))))));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n)) - l
	tmp = 0
	if m <= -54.0:
		tmp = math.cos(M) * math.exp((-0.25 * math.pow(m, 2.0)))
	elif (m <= -1.15e-227) or (not (m <= 1.15e-248) and (m <= 9.5e-170)):
		tmp = math.cos((((K * (m + n)) / 2.0) - M)) * math.exp((t_0 + (M * (n - M))))
	else:
		tmp = math.cos(M) * math.exp((t_0 - (0.5 * (n * (m + (n * 0.5))))))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(abs(Float64(m - n)) - l)
	tmp = 0.0
	if (m <= -54.0)
		tmp = Float64(cos(M) * exp(Float64(-0.25 * (m ^ 2.0))));
	elseif ((m <= -1.15e-227) || (!(m <= 1.15e-248) && (m <= 9.5e-170)))
		tmp = Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * exp(Float64(t_0 + Float64(M * Float64(n - M)))));
	else
		tmp = Float64(cos(M) * exp(Float64(t_0 - Float64(0.5 * Float64(n * Float64(m + Float64(n * 0.5)))))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((m - n)) - l;
	tmp = 0.0;
	if (m <= -54.0)
		tmp = cos(M) * exp((-0.25 * (m ^ 2.0)));
	elseif ((m <= -1.15e-227) || (~((m <= 1.15e-248)) && (m <= 9.5e-170)))
		tmp = cos((((K * (m + n)) / 2.0) - M)) * exp((t_0 + (M * (n - M))));
	else
		tmp = cos(M) * exp((t_0 - (0.5 * (n * (m + (n * 0.5))))));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, If[LessEqual[m, -54.0], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[m, -1.15e-227], And[N[Not[LessEqual[m, 1.15e-248]], $MachinePrecision], LessEqual[m, 9.5e-170]]], N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(t$95$0 + N[(M * N[(n - M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(t$95$0 - N[(0.5 * N[(n * N[(m + N[(n * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;m \leq -1.15 \cdot 10^{-227} \lor \neg \left(m \leq 1.15 \cdot 10^{-248}\right) \land m \leq 9.5 \cdot 10^{-170}:\\
\;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{t\_0 + M \cdot \left(n - M\right)}\\

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


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

    1. Initial program 76.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 98.5%

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

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

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

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

    if -54 < m < -1.15000000000000006e-227 or 1.15e-248 < m < 9.5000000000000001e-170

    1. Initial program 88.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.15000000000000006e-227 < m < 1.15e-248 or 9.5000000000000001e-170 < m

    1. Initial program 85.6%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 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. Taylor expanded in m around 0 76.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. +-commutative76.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. unpow276.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-out83.8%

        \[\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. *-commutative83.8%

        \[\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. *-commutative83.8%

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

      \[\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 M around 0 63.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq -1.15 \cdot 10^{-227} \lor \neg \left(m \leq 1.15 \cdot 10^{-248}\right) \land m \leq 9.5 \cdot 10^{-170}:\\ \;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) + M \cdot \left(n - M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - 0.5 \cdot \left(n \cdot \left(m + n \cdot 0.5\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 66.1% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -26:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq -1.5 \cdot 10^{-227} \lor \neg \left(m \leq 5.8 \cdot 10^{-265}\right) \land m \leq 4.3 \cdot 10^{-159}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot {e}^{\left(-0.25 \cdot {n}^{2}\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -26.0)
   (* (cos M) (exp (* -0.25 (pow m 2.0))))
   (if (or (<= m -1.5e-227) (and (not (<= m 5.8e-265)) (<= m 4.3e-159)))
     (* (cos M) (exp (- (pow M 2.0))))
     (* (cos M) (pow E (* -0.25 (pow n 2.0)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -26.0) {
		tmp = cos(M) * exp((-0.25 * pow(m, 2.0)));
	} else if ((m <= -1.5e-227) || (!(m <= 5.8e-265) && (m <= 4.3e-159))) {
		tmp = cos(M) * exp(-pow(M, 2.0));
	} else {
		tmp = cos(M) * pow(((double) M_E), (-0.25 * pow(n, 2.0)));
	}
	return tmp;
}
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -26.0) {
		tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(m, 2.0)));
	} else if ((m <= -1.5e-227) || (!(m <= 5.8e-265) && (m <= 4.3e-159))) {
		tmp = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
	} else {
		tmp = Math.cos(M) * Math.pow(Math.E, (-0.25 * Math.pow(n, 2.0)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -26.0:
		tmp = math.cos(M) * math.exp((-0.25 * math.pow(m, 2.0)))
	elif (m <= -1.5e-227) or (not (m <= 5.8e-265) and (m <= 4.3e-159)):
		tmp = math.cos(M) * math.exp(-math.pow(M, 2.0))
	else:
		tmp = math.cos(M) * math.pow(math.e, (-0.25 * math.pow(n, 2.0)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -26.0)
		tmp = Float64(cos(M) * exp(Float64(-0.25 * (m ^ 2.0))));
	elseif ((m <= -1.5e-227) || (!(m <= 5.8e-265) && (m <= 4.3e-159)))
		tmp = Float64(cos(M) * exp(Float64(-(M ^ 2.0))));
	else
		tmp = Float64(cos(M) * (exp(1) ^ Float64(-0.25 * (n ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -26.0)
		tmp = cos(M) * exp((-0.25 * (m ^ 2.0)));
	elseif ((m <= -1.5e-227) || (~((m <= 5.8e-265)) && (m <= 4.3e-159)))
		tmp = cos(M) * exp(-(M ^ 2.0));
	else
		tmp = cos(M) * (2.71828182845904523536 ^ (-0.25 * (n ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -26.0], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[m, -1.5e-227], And[N[Not[LessEqual[m, 5.8e-265]], $MachinePrecision], LessEqual[m, 4.3e-159]]], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Power[E, N[(-0.25 * N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;m \leq -1.5 \cdot 10^{-227} \lor \neg \left(m \leq 5.8 \cdot 10^{-265}\right) \land m \leq 4.3 \cdot 10^{-159}:\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

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


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

    1. Initial program 76.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 98.5%

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

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

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

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

    if -26 < m < -1.5e-227 or 5.7999999999999995e-265 < m < 4.3e-159

    1. Initial program 86.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 90.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-neg90.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. Simplified90.6%

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

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

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

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

    if -1.5e-227 < m < 5.7999999999999995e-265 or 4.3e-159 < m

    1. Initial program 86.3%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 98.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-neg98.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. Simplified98.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. Taylor expanded in n around inf 58.0%

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity58.0%

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

        \[\leadsto \cos M \cdot \color{blue}{{\left(e^{1}\right)}^{\left(-0.25 \cdot {n}^{2}\right)}} \]
    8. Applied egg-rr58.0%

      \[\leadsto \cos M \cdot \color{blue}{{\left(e^{1}\right)}^{\left(-0.25 \cdot {n}^{2}\right)}} \]
    9. Step-by-step derivation
      1. exp-1-e58.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -26:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq -1.5 \cdot 10^{-227} \lor \neg \left(m \leq 5.8 \cdot 10^{-265}\right) \land m \leq 4.3 \cdot 10^{-159}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot {e}^{\left(-0.25 \cdot {n}^{2}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 66.2% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;m \leq -1.1 \cdot 10^{-227} \lor \neg \left(m \leq 4 \cdot 10^{-252}\right) \land m \leq 1.1 \cdot 10^{-155}:\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

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


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

    1. Initial program 76.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 98.5%

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

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

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

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

    if -26 < m < -1.0999999999999999e-227 or 3.99999999999999977e-252 < m < 1.1e-155

    1. Initial program 88.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 91.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-neg91.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. Simplified91.6%

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

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

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

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

    if -1.0999999999999999e-227 < m < 3.99999999999999977e-252 or 1.1e-155 < m

    1. Initial program 85.6%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 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. Taylor expanded in n around inf 57.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -26:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq -1.1 \cdot 10^{-227} \lor \neg \left(m \leq 4 \cdot 10^{-252}\right) \land m \leq 1.1 \cdot 10^{-155}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 87.2% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 76.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 98.5%

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

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

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

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

    if -26 < m

    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 K around 0 95.5%

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

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

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

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

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

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

        \[\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. *-commutative86.6%

        \[\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. *-commutative86.6%

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

      \[\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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.4%

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

Alternative 11: 69.0% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 81.6%

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

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

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

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

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

    if -6.4000000000000003e-180 < n < 3.79999999999999975e23

    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 K around 0 93.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-neg93.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. Simplified93.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 68.1%

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

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

        \[\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.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. *-commutative75.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. *-commutative75.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)} \]
    8. Simplified75.4%

      \[\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 n around 0 74.6%

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

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

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

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

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

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

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

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

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

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

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

    if 3.79999999999999975e23 < n

    1. Initial program 83.1%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Step-by-step derivation
      1. *-un-lft-identity100.0%

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

        \[\leadsto \cos M \cdot \color{blue}{{\left(e^{1}\right)}^{\left(-0.25 \cdot {n}^{2}\right)}} \]
    8. Applied egg-rr100.0%

      \[\leadsto \cos M \cdot \color{blue}{{\left(e^{1}\right)}^{\left(-0.25 \cdot {n}^{2}\right)}} \]
    9. Step-by-step derivation
      1. exp-1-e100.0%

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

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

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

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

Alternative 12: 66.5% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -4 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -3 \cdot 10^{-215}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -4.0000000000000003e-15 or 1.25e-14 < M

    1. Initial program 89.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 99.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-neg99.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. Simplified99.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. Taylor expanded in M around inf 95.2%

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

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

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

    if -4.0000000000000003e-15 < M < -3.00000000000000025e-215

    1. Initial program 80.3%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 93.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-neg93.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. Simplified93.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. Taylor expanded in l around inf 31.2%

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

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

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

    if -3.00000000000000025e-215 < M < 1.25e-14

    1. Initial program 74.5%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 92.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-neg92.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. Simplified92.0%

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

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

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

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

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

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

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

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

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

Alternative 13: 63.3% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 76.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 98.5%

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

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

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

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

    if -26 < m < 5.50000000000000032e-103

    1. Initial program 86.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 93.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-neg93.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. Simplified93.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. Taylor expanded in M around inf 61.0%

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

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

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

    if 5.50000000000000032e-103 < m

    1. Initial program 87.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 98.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-neg98.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. Simplified98.6%

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

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

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

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

        \[\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. *-commutative77.1%

        \[\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. *-commutative77.1%

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

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

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

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

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

Alternative 14: 53.8% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 82.6%

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

      \[\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. +-commutative78.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. unpow278.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-out83.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. *-commutative83.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. *-commutative83.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)} \]
    8. Simplified83.3%

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

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

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

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

    if 3.80000000000000008e-32 < l

    1. Initial program 87.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. Taylor expanded in l around inf 91.5%

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

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

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

Alternative 15: 35.9% accurate, 2.1× speedup?

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

\\
\cos M \cdot e^{-\ell}
\end{array}
Derivation
  1. Initial program 83.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 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. Taylor expanded in l around inf 29.0%

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

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

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

Alternative 16: 35.5% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 83.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 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. Taylor expanded in l around inf 29.0%

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

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

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

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

Alternative 17: 7.1% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 83.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 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. Taylor expanded in l around inf 29.0%

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

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

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

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

Reproduce

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