Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 96.8%
Time: 23.8s
Alternatives: 7
Speedup: 3.7×

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 7 alternatives:

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

Initial Program: 76.3% accurate, 1.0× speedup?

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

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

Alternative 1: 96.8% accurate, 0.3× speedup?

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

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

\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)))))) < 0.5

    1. Initial program 96.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. Step-by-step derivation
      1. add-log-exp96.7%

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

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

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

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

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

      \[\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)} \]
    5. Taylor expanded in l around inf 96.7%

      \[\leadsto \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) - \color{blue}{\ell}} \]
    6. Step-by-step derivation
      1. add-cube-cbrt96.7%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, -M\right)\right)}} \cdot \sqrt[3]{e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, -M\right)\right)}}\right) \cdot \sqrt[3]{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) - \ell} \]
      2. pow396.7%

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

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

        \[\leadsto \log \left({\left(\sqrt[3]{e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, \color{blue}{\sqrt{\left(-M\right) \cdot \left(-M\right)}}\right)\right)}}\right)}^{3}\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell} \]
      5. sqr-neg69.8%

        \[\leadsto \log \left({\left(\sqrt[3]{e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, \sqrt{\color{blue}{M \cdot M}}\right)\right)}}\right)}^{3}\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell} \]
      6. sqrt-unprod40.8%

        \[\leadsto \log \left({\left(\sqrt[3]{e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, \color{blue}{\sqrt{M} \cdot \sqrt{M}}\right)\right)}}\right)}^{3}\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell} \]
      7. add-sqr-sqrt96.7%

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

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

    if 0.5 < (*.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.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 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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.3%

    \[\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.5:\\ \;\;\;\;\log \left({\left(\sqrt[3]{e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, M\right)\right)}}\right)}^{3}\right) \cdot e^{\left(-\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 2: 96.8% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := {\left(\frac{m + n}{2} - M\right)}^{2}\\
t_1 := e^{\left(\left|m - n\right| - \ell\right) - t\_0}\\
\mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_1 \leq 0.5:\\
\;\;\;\;e^{\left(-\ell\right) - 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\_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)))))) < 0.5

    1. Initial program 96.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. Step-by-step derivation
      1. add-log-exp96.7%

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

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

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

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

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

      \[\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)} \]
    5. Taylor expanded in l around inf 96.7%

      \[\leadsto \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) - \color{blue}{\ell}} \]

    if 0.5 < (*.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.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 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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.3%

    \[\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.5:\\ \;\;\;\;e^{\left(-\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 3: 96.8% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;t\_2 \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.5

    1. Initial program 96.7%

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

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

    if 0.5 < (*.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.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 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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.3%

    \[\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.5:\\ \;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\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 4: 96.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ e^{\left(-\ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos M \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (* (exp (- (- 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((-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((-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((-l - Math.pow((((m + n) / 2.0) - M), 2.0))) * Math.cos(M);
}
def code(K, m, n, M, l):
	return math.exp((-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(-l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))) * cos(M))
end
function tmp = code(K, m, n, M, l)
	tmp = exp((-l - ((((m + n) / 2.0) - M) ^ 2.0))) * cos(M);
end
code[K_, m_, n_, M_, l_] := N[(N[Exp[N[((-l) - 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(-\ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos M
\end{array}
Derivation
  1. Initial program 77.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 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 l around inf 95.4%

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

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

Alternative 5: 86.6% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 70.0%

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

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

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

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

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

        \[\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) - \ell} \]
      4. *-commutative57.7%

        \[\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) - \ell} \]
      5. *-commutative57.7%

        \[\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) - \ell} \]
    6. Simplified57.7%

      \[\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) - \ell} \]
    7. Taylor expanded in m around inf 57.7%

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

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

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

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

    if -1.9999999999999999e112 < m

    1. Initial program 78.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 94.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-neg94.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. Simplified94.7%

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

      \[\leadsto \cos M \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \color{blue}{\ell}} \]
    7. Taylor expanded in m around 0 80.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) - \ell} \]
    8. Step-by-step derivation
      1. +-commutative80.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) - \ell} \]
      2. unpow280.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) - \ell} \]
      3. distribute-rgt-out85.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) - \ell} \]
      4. *-commutative85.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) - \ell} \]
      5. *-commutative85.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) - \ell} \]
    9. Simplified85.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) - \ell} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.8%

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

Alternative 6: 86.8% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 79.4%

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

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

      \[\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) - \ell} \]
    5. Step-by-step derivation
      1. +-commutative66.4%

        \[\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) - \ell} \]
      2. unpow266.4%

        \[\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) - \ell} \]
      3. distribute-rgt-out73.1%

        \[\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) - \ell} \]
      4. *-commutative73.1%

        \[\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) - \ell} \]
      5. *-commutative73.1%

        \[\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) - \ell} \]
    6. Simplified73.1%

      \[\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) - \ell} \]
    7. Taylor expanded in K around 0 84.9%

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

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

    if 1.45000000000000005e105 < n

    1. Initial program 68.1%

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

      \[\leadsto \cos M \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \color{blue}{\ell}} \]
    7. Taylor expanded in m around 0 78.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) - \ell} \]
    8. Step-by-step derivation
      1. +-commutative78.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) - \ell} \]
      2. unpow278.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) - \ell} \]
      3. distribute-rgt-out95.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) - \ell} \]
      4. *-commutative95.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) - \ell} \]
      5. *-commutative95.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) - \ell} \]
    9. Simplified95.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) - \ell} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification86.9%

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

Alternative 7: 81.4% accurate, 3.7× speedup?

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

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

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

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

    \[\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) - \ell} \]
  5. Step-by-step derivation
    1. +-commutative59.7%

      \[\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) - \ell} \]
    2. unpow259.7%

      \[\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) - \ell} \]
    3. distribute-rgt-out67.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) - \ell} \]
    4. *-commutative67.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) - \ell} \]
    5. *-commutative67.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) - \ell} \]
  6. Simplified67.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) - \ell} \]
  7. Taylor expanded in m around inf 68.9%

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

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

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

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

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

Reproduce

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