Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.1% → 96.5%
Time: 31.7s
Alternatives: 10
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 10 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.5% accurate, 1.0× speedup?

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

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

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

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

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

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

Alternative 2: 63.0% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\left(m + 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)\right) - \left(n + \ell\right)}\\
t_1 := \cos M \cdot e^{M \cdot \left(n - M\right) + \left(\left|m - n\right| - \ell\right)}\\
\mathbf{if}\;m \leq -55:\\
\;\;\;\;e^{-0.25 \cdot {m}^{2}}\\

\mathbf{elif}\;m \leq -2 \cdot 10^{-205}:\\
\;\;\;\;t\_0 \cdot \cos \left(\frac{m \cdot K}{2} - M\right)\\

\mathbf{elif}\;m \leq 7.4 \cdot 10^{-269}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;m \leq 3.6 \cdot 10^{-96}:\\
\;\;\;\;\cos \left(-M\right) \cdot t\_0\\

\mathbf{elif}\;m \leq 1.15 \cdot 10^{-45}:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 75.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 98.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutative98.3%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Taylor expanded in M around 0 98.3%

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

    if -55 < m < -2e-205

    1. Initial program 80.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. Step-by-step derivation
      1. *-un-lft-identity80.0%

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

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

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

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

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

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

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

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

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

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

    if -2e-205 < m < 7.39999999999999955e-269 or 3.60000000000000008e-96 < m < 1.14999999999999996e-45

    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. Taylor expanded in K around 0 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|-\left(n + -1 \cdot m\right)\right| - \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(n - M\right)} \]
      8. cancel-sign-sub84.0%

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

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

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

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

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

    if 7.39999999999999955e-269 < m < 3.60000000000000008e-96

    1. Initial program 88.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. Step-by-step derivation
      1. *-un-lft-identity88.9%

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

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

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

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

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

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

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

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

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

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

    if 1.14999999999999996e-45 < m

    1. Initial program 71.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 79.9% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 78.4%

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

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

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

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

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

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

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

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

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

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

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

    if 1.8e92 < n

    1. Initial program 78.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. *-un-lft-identity78.4%

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 87.3% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 75.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 98.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutative98.3%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Taylor expanded in M around 0 98.3%

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

    if -6e8 < m

    1. Initial program 79.3%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 61.1% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(m + 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)\right) - \left(n + \ell\right)}\\ \mathbf{if}\;m \leq -53:\\ \;\;\;\;e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq -2.5 \cdot 10^{-265}:\\ \;\;\;\;t\_0 \cdot \cos \left(\frac{m \cdot K}{2} - M\right)\\ \mathbf{elif}\;m \leq 4.7 \cdot 10^{-268}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{elif}\;m \leq 1.24 \cdot 10^{-45}:\\ \;\;\;\;\cos \left(-M\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- (+ m (* 0.5 (* m (+ n (* m 0.5))))) (+ n l)))))
   (if (<= m -53.0)
     (exp (* -0.25 (pow m 2.0)))
     (if (<= m -2.5e-265)
       (* t_0 (cos (- (/ (* m K) 2.0) M)))
       (if (<= m 4.7e-268)
         (* (cos M) (exp (- (pow M 2.0))))
         (if (<= m 1.24e-45)
           (* (cos (- M)) t_0)
           (* (cos M) (exp (* n (* m -0.5))))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(((m + (0.5 * (m * (n + (m * 0.5))))) - (n + l)));
	double tmp;
	if (m <= -53.0) {
		tmp = exp((-0.25 * pow(m, 2.0)));
	} else if (m <= -2.5e-265) {
		tmp = t_0 * cos((((m * K) / 2.0) - M));
	} else if (m <= 4.7e-268) {
		tmp = cos(M) * exp(-pow(M, 2.0));
	} else if (m <= 1.24e-45) {
		tmp = cos(-M) * t_0;
	} else {
		tmp = cos(M) * exp((n * (m * -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 = exp(((m + (0.5d0 * (m * (n + (m * 0.5d0))))) - (n + l)))
    if (m <= (-53.0d0)) then
        tmp = exp(((-0.25d0) * (m ** 2.0d0)))
    else if (m <= (-2.5d-265)) then
        tmp = t_0 * cos((((m * k) / 2.0d0) - m_1))
    else if (m <= 4.7d-268) then
        tmp = cos(m_1) * exp(-(m_1 ** 2.0d0))
    else if (m <= 1.24d-45) then
        tmp = cos(-m_1) * t_0
    else
        tmp = cos(m_1) * exp((n * (m * (-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.exp(((m + (0.5 * (m * (n + (m * 0.5))))) - (n + l)));
	double tmp;
	if (m <= -53.0) {
		tmp = Math.exp((-0.25 * Math.pow(m, 2.0)));
	} else if (m <= -2.5e-265) {
		tmp = t_0 * Math.cos((((m * K) / 2.0) - M));
	} else if (m <= 4.7e-268) {
		tmp = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
	} else if (m <= 1.24e-45) {
		tmp = Math.cos(-M) * t_0;
	} else {
		tmp = Math.cos(M) * Math.exp((n * (m * -0.5)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp(((m + (0.5 * (m * (n + (m * 0.5))))) - (n + l)))
	tmp = 0
	if m <= -53.0:
		tmp = math.exp((-0.25 * math.pow(m, 2.0)))
	elif m <= -2.5e-265:
		tmp = t_0 * math.cos((((m * K) / 2.0) - M))
	elif m <= 4.7e-268:
		tmp = math.cos(M) * math.exp(-math.pow(M, 2.0))
	elif m <= 1.24e-45:
		tmp = math.cos(-M) * t_0
	else:
		tmp = math.cos(M) * math.exp((n * (m * -0.5)))
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(Float64(m + Float64(0.5 * Float64(m * Float64(n + Float64(m * 0.5))))) - Float64(n + l)))
	tmp = 0.0
	if (m <= -53.0)
		tmp = exp(Float64(-0.25 * (m ^ 2.0)));
	elseif (m <= -2.5e-265)
		tmp = Float64(t_0 * cos(Float64(Float64(Float64(m * K) / 2.0) - M)));
	elseif (m <= 4.7e-268)
		tmp = Float64(cos(M) * exp(Float64(-(M ^ 2.0))));
	elseif (m <= 1.24e-45)
		tmp = Float64(cos(Float64(-M)) * t_0);
	else
		tmp = Float64(cos(M) * exp(Float64(n * Float64(m * -0.5))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((m + (0.5 * (m * (n + (m * 0.5))))) - (n + l)));
	tmp = 0.0;
	if (m <= -53.0)
		tmp = exp((-0.25 * (m ^ 2.0)));
	elseif (m <= -2.5e-265)
		tmp = t_0 * cos((((m * K) / 2.0) - M));
	elseif (m <= 4.7e-268)
		tmp = cos(M) * exp(-(M ^ 2.0));
	elseif (m <= 1.24e-45)
		tmp = cos(-M) * t_0;
	else
		tmp = cos(M) * exp((n * (m * -0.5)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[(m + N[(0.5 * N[(m * N[(n + N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(n + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[m, -53.0], N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -2.5e-265], N[(t$95$0 * N[Cos[N[(N[(N[(m * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 4.7e-268], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 1.24e-45], N[(N[Cos[(-M)], $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(n * N[(m * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\left(m + 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)\right) - \left(n + \ell\right)}\\
\mathbf{if}\;m \leq -53:\\
\;\;\;\;e^{-0.25 \cdot {m}^{2}}\\

\mathbf{elif}\;m \leq -2.5 \cdot 10^{-265}:\\
\;\;\;\;t\_0 \cdot \cos \left(\frac{m \cdot K}{2} - M\right)\\

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

\mathbf{elif}\;m \leq 1.24 \cdot 10^{-45}:\\
\;\;\;\;\cos \left(-M\right) \cdot t\_0\\

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


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

    1. Initial program 75.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 98.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutative98.3%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Taylor expanded in M around 0 98.3%

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

    if -53 < m < -2.5e-265

    1. Initial program 82.6%

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

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

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

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

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

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

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

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

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

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

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

    if -2.5e-265 < m < 4.69999999999999973e-268

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.69999999999999973e-268 < m < 1.24e-45

    1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

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

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

    if 1.24e-45 < m

    1. Initial program 71.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 60.8% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 75.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 98.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutative98.3%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Taylor expanded in M around 0 98.3%

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

    if -55 < m < 1.24e-45

    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. Step-by-step derivation
      1. *-un-lft-identity85.8%

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

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

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

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

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

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

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

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

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

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

    if 1.24e-45 < m

    1. Initial program 71.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 58.3% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 75.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 98.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutative98.3%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Taylor expanded in M around 0 98.3%

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

    if -53 < m < 2.00000000000000002e-50

    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. Step-by-step derivation
      1. *-un-lft-identity85.7%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) \cdot e^{-\left(\ell + n\right)}} \]
    10. Step-by-step derivation
      1. exp-neg52.4%

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

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

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

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

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

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

    if 2.00000000000000002e-50 < m

    1. Initial program 71.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 98.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 49.8% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq 1.12 \cdot 10^{-237}:\\
\;\;\;\;\cos M \cdot e^{M \cdot n}\\

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


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

    1. Initial program 75.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 98.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutative98.3%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Taylor expanded in M around 0 98.3%

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

    if -53 < m < 1.12000000000000002e-237

    1. Initial program 83.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.12000000000000002e-237 < m

    1. Initial program 77.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 65.5% accurate, 2.0× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutative97.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    11. Simplified97.8%

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    12. Taylor expanded in M around 0 97.8%

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

    if -55 < m < 53

    1. Initial program 84.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 54.1% accurate, 2.1× speedup?

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

\\
e^{-0.25 \cdot {m}^{2}}
\end{array}
Derivation
  1. Initial program 78.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 97.4%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
  10. Step-by-step derivation
    1. *-commutative57.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  11. Simplified57.1%

    \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  12. Taylor expanded in M around 0 57.0%

    \[\leadsto \color{blue}{e^{-0.25 \cdot {m}^{2}}} \]
  13. Final simplification57.0%

    \[\leadsto e^{-0.25 \cdot {m}^{2}} \]
  14. Add Preprocessing

Reproduce

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