Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.4% → 97.1%
Time: 17.2s
Alternatives: 15
Speedup: 1.8×

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 15 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.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: 97.1% 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}}\\ \mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_0 \leq \infty:\\ \;\;\;\;t\_0 \cdot \cos \left(\frac{1}{\frac{\frac{2}{m + n}}{K}} - M\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) INFINITY)
     (* t_0 (cos (- (/ 1.0 (/ (/ 2.0 (+ m n)) K)) 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) <= ((double) INFINITY)) {
		tmp = t_0 * cos(((1.0 / ((2.0 / (m + n)) / K)) - M));
	} else {
		tmp = t_0 * cos(M);
	}
	return tmp;
}
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 tmp;
	if ((Math.cos((((K * (m + n)) / 2.0) - M)) * t_0) <= Double.POSITIVE_INFINITY) {
		tmp = t_0 * Math.cos(((1.0 / ((2.0 / (m + n)) / K)) - M));
	} 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)))
	tmp = 0
	if (math.cos((((K * (m + n)) / 2.0) - M)) * t_0) <= math.inf:
		tmp = t_0 * math.cos(((1.0 / ((2.0 / (m + n)) / K)) - M))
	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)))
	tmp = 0.0
	if (Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * t_0) <= Inf)
		tmp = Float64(t_0 * cos(Float64(Float64(1.0 / Float64(Float64(2.0 / Float64(m + n)) / K)) - M)));
	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)));
	tmp = 0.0;
	if ((cos((((K * (m + n)) / 2.0) - M)) * t_0) <= Inf)
		tmp = t_0 * cos(((1.0 / ((2.0 / (m + n)) / K)) - M));
	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]}, If[LessEqual[N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], Infinity], N[(t$95$0 * N[Cos[N[(N[(1.0 / N[(N[(2.0 / N[(m + n), $MachinePrecision]), $MachinePrecision] / K), $MachinePrecision]), $MachinePrecision] - M), $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 \infty:\\
\;\;\;\;t\_0 \cdot \cos \left(\frac{1}{\frac{\frac{2}{m + n}}{K}} - M\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)))))) < +inf.0

    1. Initial program 95.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. Step-by-step derivation
      1. clear-num96.3%

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

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

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

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

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

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

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

    if +inf.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 0.0%

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

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

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  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 \infty:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{1}{\frac{\frac{2}{m + n}}{K}} - M\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.8% 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 75.9%

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

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

Alternative 3: 90.7% accurate, 1.3× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000007e42 < n

    1. Initial program 69.6%

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

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

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

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

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

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

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

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

Alternative 4: 90.6% accurate, 1.8× speedup?

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

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

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


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

    1. Initial program 77.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. sub-neg77.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.99999999999999982e38 < n

    1. Initial program 70.2%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Taylor expanded in M around 0 95.8%

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

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

Alternative 5: 82.4% accurate, 1.8× speedup?

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

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

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


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

    1. Initial program 77.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999973e48 < n

    1. Initial program 68.2%

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

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

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

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

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

Alternative 6: 65.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\
\mathbf{if}\;\ell \leq -4.5 \cdot 10^{-182}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-171}:\\
\;\;\;\;\left(0.5 \cdot {\ell}^{2}\right) \cdot \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right)\\

\mathbf{elif}\;\ell \leq 2.4 \cdot 10^{-23}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.4999999999999999e-182 or 1.30000000000000002e-171 < l < 2.39999999999999996e-23

    1. Initial program 75.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 94.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-neg94.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. Simplified94.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 n around inf 47.5%

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

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

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

    if -4.4999999999999999e-182 < l < 1.30000000000000002e-171

    1. Initial program 80.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 11.8%

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

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

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

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

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

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

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

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

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

    if 2.39999999999999996e-23 < l

    1. Initial program 72.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 70.2%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.5 \cdot 10^{-182}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-171}:\\ \;\;\;\;\left(0.5 \cdot {\ell}^{2}\right) \cdot \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right)\\ \mathbf{elif}\;\ell \leq 2.4 \cdot 10^{-23}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 69.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -55:\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\

\mathbf{elif}\;n \leq 13.5:\\
\;\;\;\;e^{-\ell} \cdot \cos \left(K \cdot \frac{1}{\frac{2}{n}} - M\right)\\

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


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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Taylor expanded in M around 0 95.6%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]

    if -55 < n < 13.5

    1. Initial program 85.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 37.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 13.5 < n

    1. Initial program 74.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.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 91.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -55:\\ \;\;\;\;e^{-0.25 \cdot {n}^{2}}\\ \mathbf{elif}\;n \leq 13.5:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(K \cdot \frac{1}{\frac{2}{n}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 69.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -54:\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\

\mathbf{elif}\;n \leq 13.5:\\
\;\;\;\;\cos \left(\frac{K \cdot n}{2} - M\right) \cdot e^{-\ell}\\

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


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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Taylor expanded in M around 0 95.6%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]

    if -54 < n < 13.5

    1. Initial program 85.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 37.8%

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

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

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

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

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

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

    if 13.5 < n

    1. Initial program 74.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.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 91.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -54:\\ \;\;\;\;e^{-0.25 \cdot {n}^{2}}\\ \mathbf{elif}\;n \leq 13.5:\\ \;\;\;\;\cos \left(\frac{K \cdot n}{2} - M\right) \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 69.1% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -54:\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\

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

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


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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Taylor expanded in M around 0 95.6%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]

    if -54 < n < 4.60000000000000014e-10

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

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

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

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

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

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

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

    if 4.60000000000000014e-10 < n

    1. Initial program 75.0%

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

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

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

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

Alternative 10: 69.1% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -54 \lor \neg \left(n \leq 4.6 \cdot 10^{-10}\right):\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -54 or 4.60000000000000014e-10 < n

    1. Initial program 66.9%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Taylor expanded in M around 0 92.3%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]

    if -54 < n < 4.60000000000000014e-10

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -54 \lor \neg \left(n \leq 4.6 \cdot 10^{-10}\right):\\ \;\;\;\;e^{-0.25 \cdot {n}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 53.4% accurate, 2.1× speedup?

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

\\
e^{-0.25 \cdot {n}^{2}}
\end{array}
Derivation
  1. Initial program 75.9%

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
  7. Taylor expanded in M around 0 51.9%

    \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]
  8. Add Preprocessing

Alternative 12: 9.6% accurate, 3.5× speedup?

\[\begin{array}{l} \\ \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right) \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (*
  (cos (- (/ (* K (+ m n)) 2.0) M))
  (+ 1.0 (* l (+ (* l (+ 0.5 (* l -0.16666666666666666))) -1.0)))))
double code(double K, double m, double n, double M, double l) {
	return cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = cos((((k * (m + n)) / 2.0d0) - m_1)) * (1.0d0 + (l * ((l * (0.5d0 + (l * (-0.16666666666666666d0)))) + (-1.0d0))))
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)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
}
def code(K, m, n, M, l):
	return math.cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)))
function code(K, m, n, M, l)
	return Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * Float64(1.0 + Float64(l * Float64(Float64(l * Float64(0.5 + Float64(l * -0.16666666666666666))) + -1.0))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
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[(1.0 + N[(l * N[(N[(l * N[(0.5 + N[(l * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right)
\end{array}
Derivation
  1. Initial program 75.9%

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

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

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

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

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + -0.16666666666666666 \cdot \ell\right) - 1\right)\right)} \]
  7. Final simplification9.4%

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

Alternative 13: 9.1% accurate, 3.8× speedup?

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

\\
\cos M \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.5 + -1\right)\right)
\end{array}
Derivation
  1. Initial program 75.9%

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

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot \left(1 + \ell \cdot \left(0.5 \cdot \ell - 1\right)\right) \]
  8. Step-by-step derivation
    1. cos-neg96.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)} \]
  9. Simplified9.2%

    \[\leadsto \color{blue}{\cos M} \cdot \left(1 + \ell \cdot \left(0.5 \cdot \ell - 1\right)\right) \]
  10. Final simplification9.2%

    \[\leadsto \cos M \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.5 + -1\right)\right) \]
  11. Add Preprocessing

Alternative 14: 6.7% 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 75.9%

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
  7. Taylor expanded in n around 0 7.5%

    \[\leadsto \cos M \cdot \color{blue}{1} \]
  8. Taylor expanded in M around inf 7.5%

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

Alternative 15: 6.7% accurate, 425.0× speedup?

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
  7. Taylor expanded in n around 0 7.5%

    \[\leadsto \cos M \cdot \color{blue}{1} \]
  8. Taylor expanded in M around 0 7.5%

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

Reproduce

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