Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.1% → 96.8%
Time: 29.4s
Alternatives: 12
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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

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

Alternative 1: 96.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 87.0% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 67.3%

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

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

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

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

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

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

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

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

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

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

    if -3.49999999999999985e46 < m

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(-1 \cdot M + 0.5 \cdot n\right) \cdot \left(m + \left(\color{blue}{-1 \cdot M} + 0.5 \cdot n\right)\right)} \]
      10. *-commutative82.9%

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(0.5 \cdot n + \left(-M\right)\right)} \cdot \left(m + \left(-1 \cdot M + 0.5 \cdot n\right)\right)} \]
      14. sub-neg82.9%

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

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

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

Alternative 3: 85.8% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;m \leq -3.5 \cdot 10^{+46}:\\
\;\;\;\;0.5 \cdot \left(\left(m \cdot K\right) \cdot \left(M \cdot e^{t\_0 - \left(0.25 \cdot {\left(m + n\right)}^{2} + \ell\right)}\right)\right)\\

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


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

    1. Initial program 56.4%

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

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

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

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

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

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

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

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

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

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

    if -8.5e139 < m < -3.49999999999999985e46

    1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

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

    if -3.49999999999999985e46 < m

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(-1 \cdot M + 0.5 \cdot n\right) \cdot \left(m + \left(\color{blue}{-1 \cdot M} + 0.5 \cdot n\right)\right)} \]
      10. *-commutative82.9%

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(0.5 \cdot n + \left(-M\right)\right)} \cdot \left(m + \left(-1 \cdot M + 0.5 \cdot n\right)\right)} \]
      14. sub-neg82.9%

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

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

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

Alternative 4: 84.4% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 67.3%

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

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

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

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

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

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

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

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

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

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

    if -3.49999999999999985e46 < m

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \left(-1 \cdot M + 0.5 \cdot n\right) \cdot \left(m + \left(\color{blue}{-1 \cdot M} + 0.5 \cdot n\right)\right)} \]
      10. *-commutative82.9%

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(0.5 \cdot n + \left(-M\right)\right)} \cdot \left(m + \left(-1 \cdot M + 0.5 \cdot n\right)\right)} \]
      14. sub-neg82.9%

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

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

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

Alternative 5: 78.3% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -3800000000000 \lor \neg \left(M \leq 34\right):\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -3.8e12 or 34 < M

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.8e12 < M < 34

    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. exp-diff23.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\left(\left(n \cdot 0.5 - M\right) \cdot m + \color{blue}{\left(n \cdot 0.5 - M\right) \cdot \left(n \cdot 0.5 - M\right)}\right) - \left(n + \left(\ell - m\right)\right)} \]
      5. distribute-lft-in37.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 65.4% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{M \cdot \left(m - M\right)}\\ \mathbf{if}\;M \leq -1.55 \cdot 10^{+192}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq -1.55 \cdot 10^{+126}:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\ \mathbf{elif}\;M \leq -1.35 \cdot 10^{+47} \lor \neg \left(M \leq 1.2 \cdot 10^{+17}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(M - n \cdot 0.5\right) + \left(\left(m - \ell\right) - n\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos (- (* 0.5 (* m K)) M)) (exp (* M (- m M))))))
   (if (<= M -1.55e+192)
     t_0
     (if (<= M -1.55e+126)
       (* (cos M) (exp (* m (- (+ (* n 0.5) 1.0) M))))
       (if (or (<= M -1.35e+47) (not (<= M 1.2e+17)))
         t_0
         (* (cos M) (exp (+ (* M (- M (* n 0.5))) (- (- m l) n)))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(((0.5 * (m * K)) - M)) * exp((M * (m - M)));
	double tmp;
	if (M <= -1.55e+192) {
		tmp = t_0;
	} else if (M <= -1.55e+126) {
		tmp = cos(M) * exp((m * (((n * 0.5) + 1.0) - M)));
	} else if ((M <= -1.35e+47) || !(M <= 1.2e+17)) {
		tmp = t_0;
	} else {
		tmp = cos(M) * exp(((M * (M - (n * 0.5))) + ((m - l) - 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 = cos(((0.5d0 * (m * k)) - m_1)) * exp((m_1 * (m - m_1)))
    if (m_1 <= (-1.55d+192)) then
        tmp = t_0
    else if (m_1 <= (-1.55d+126)) then
        tmp = cos(m_1) * exp((m * (((n * 0.5d0) + 1.0d0) - m_1)))
    else if ((m_1 <= (-1.35d+47)) .or. (.not. (m_1 <= 1.2d+17))) then
        tmp = t_0
    else
        tmp = cos(m_1) * exp(((m_1 * (m_1 - (n * 0.5d0))) + ((m - l) - n)))
    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(((0.5 * (m * K)) - M)) * Math.exp((M * (m - M)));
	double tmp;
	if (M <= -1.55e+192) {
		tmp = t_0;
	} else if (M <= -1.55e+126) {
		tmp = Math.cos(M) * Math.exp((m * (((n * 0.5) + 1.0) - M)));
	} else if ((M <= -1.35e+47) || !(M <= 1.2e+17)) {
		tmp = t_0;
	} else {
		tmp = Math.cos(M) * Math.exp(((M * (M - (n * 0.5))) + ((m - l) - n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(((0.5 * (m * K)) - M)) * math.exp((M * (m - M)))
	tmp = 0
	if M <= -1.55e+192:
		tmp = t_0
	elif M <= -1.55e+126:
		tmp = math.cos(M) * math.exp((m * (((n * 0.5) + 1.0) - M)))
	elif (M <= -1.35e+47) or not (M <= 1.2e+17):
		tmp = t_0
	else:
		tmp = math.cos(M) * math.exp(((M * (M - (n * 0.5))) + ((m - l) - n)))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(Float64(Float64(0.5 * Float64(m * K)) - M)) * exp(Float64(M * Float64(m - M))))
	tmp = 0.0
	if (M <= -1.55e+192)
		tmp = t_0;
	elseif (M <= -1.55e+126)
		tmp = Float64(cos(M) * exp(Float64(m * Float64(Float64(Float64(n * 0.5) + 1.0) - M))));
	elseif ((M <= -1.35e+47) || !(M <= 1.2e+17))
		tmp = t_0;
	else
		tmp = Float64(cos(M) * exp(Float64(Float64(M * Float64(M - Float64(n * 0.5))) + Float64(Float64(m - l) - n))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = cos(((0.5 * (m * K)) - M)) * exp((M * (m - M)));
	tmp = 0.0;
	if (M <= -1.55e+192)
		tmp = t_0;
	elseif (M <= -1.55e+126)
		tmp = cos(M) * exp((m * (((n * 0.5) + 1.0) - M)));
	elseif ((M <= -1.35e+47) || ~((M <= 1.2e+17)))
		tmp = t_0;
	else
		tmp = cos(M) * exp(((M * (M - (n * 0.5))) + ((m - l) - n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[N[(N[(0.5 * N[(m * K), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(M * N[(m - M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -1.55e+192], t$95$0, If[LessEqual[M, -1.55e+126], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(m * N[(N[(N[(n * 0.5), $MachinePrecision] + 1.0), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[M, -1.35e+47], N[Not[LessEqual[M, 1.2e+17]], $MachinePrecision]], t$95$0, N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(M * N[(M - N[(n * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(m - l), $MachinePrecision] - n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;M \leq -1.35 \cdot 10^{+47} \lor \neg \left(M \leq 1.2 \cdot 10^{+17}\right):\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -1.5499999999999999e192 or -1.55e126 < M < -1.34999999999999998e47 or 1.2e17 < M

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{M \cdot m + \left(-\color{blue}{M \cdot M}\right)} \]
      4. distribute-rgt-neg-in78.1%

        \[\leadsto \cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{M \cdot m + \color{blue}{M \cdot \left(-M\right)}} \]
      5. distribute-lft-in84.1%

        \[\leadsto \cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{\color{blue}{M \cdot \left(m + \left(-M\right)\right)}} \]
      6. sub-neg84.1%

        \[\leadsto \cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{M \cdot \color{blue}{\left(m - M\right)}} \]
    11. Simplified84.1%

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

    if -1.5499999999999999e192 < M < -1.55e126

    1. Initial program 62.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. exp-diff12.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.34999999999999998e47 < M < 1.2e17

    1. Initial program 76.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -1.55 \cdot 10^{+192}:\\ \;\;\;\;\cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{M \cdot \left(m - M\right)}\\ \mathbf{elif}\;M \leq -1.55 \cdot 10^{+126}:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\ \mathbf{elif}\;M \leq -1.35 \cdot 10^{+47} \lor \neg \left(M \leq 1.2 \cdot 10^{+17}\right):\\ \;\;\;\;\cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{M \cdot \left(m - M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(M - n \cdot 0.5\right) + \left(\left(m - \ell\right) - n\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 70.2% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := e^{-0.25 \cdot {n}^{2}}\\
\mathbf{if}\;n \leq -2.9 \cdot 10^{-19}:\\
\;\;\;\;t\_0\\

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

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

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

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


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

    1. Initial program 77.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 0 75.1%

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

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

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

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

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

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

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

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

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

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

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

    if -2.9e-19 < n < 2.2e-263

    1. Initial program 89.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. exp-diff47.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\left(\left(n \cdot 0.5 - M\right) \cdot m + \color{blue}{\left(n \cdot 0.5 - M\right) \cdot \left(n \cdot 0.5 - M\right)}\right) - \left(n + \left(\ell - m\right)\right)} \]
      5. distribute-lft-in36.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.2e-263 < n < 1.3e-28

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{M \cdot m + \color{blue}{M \cdot \left(-M\right)}} \]
      5. distribute-lft-in57.9%

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

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

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

    if 1.3e-28 < n < 54

    1. Initial program 50.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -2.9 \cdot 10^{-19}:\\ \;\;\;\;e^{-0.25 \cdot {n}^{2}}\\ \mathbf{elif}\;n \leq 2.2 \cdot 10^{-263}:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\ \mathbf{elif}\;n \leq 1.3 \cdot 10^{-28}:\\ \;\;\;\;\cos \left(0.5 \cdot \left(m \cdot K\right) - M\right) \cdot e^{M \cdot \left(m - M\right)}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot {n}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 75.5% accurate, 1.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -53 or 56 < n

    1. Initial program 77.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -53 < n < 56

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 68.2% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 77.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 0 75.1%

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

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

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

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

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

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

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

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

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

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

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

    if -2.9e-19 < n < 54

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 68.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq -2.4 \cdot 10^{-47} \lor \neg \left(n \leq 54\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 -2.4e-47) (not (<= n 54.0)))
   (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 <= -2.4e-47) || !(n <= 54.0)) {
		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 <= (-2.4d-47)) .or. (.not. (n <= 54.0d0))) 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 <= -2.4e-47) || !(n <= 54.0)) {
		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 <= -2.4e-47) or not (n <= 54.0):
		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 <= -2.4e-47) || !(n <= 54.0))
		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 <= -2.4e-47) || ~((n <= 54.0)))
		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, -2.4e-47], N[Not[LessEqual[n, 54.0]], $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 -2.4 \cdot 10^{-47} \lor \neg \left(n \leq 54\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 < -2.3999999999999999e-47 or 54 < n

    1. Initial program 78.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.3999999999999999e-47 < n < 54

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 54.1% 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 81.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]
  11. Final simplification55.3%

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

Alternative 12: 7.0% 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 81.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos M} \]
  11. Final simplification7.3%

    \[\leadsto \cos M \]
  12. Add Preprocessing

Reproduce

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