Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.0% → 96.5%
Time: 35.3s
Alternatives: 20
Speedup: 1.9×

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 20 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.0% 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(M \cdot \left(0.5 \cdot \frac{m + n}{M} + -1\right)\right)}^{2}} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (*
  (cos M)
  (exp
   (- (- (fabs (- m n)) l) (pow (* M (+ (* 0.5 (/ (+ m n) M)) -1.0)) 2.0)))))
double code(double K, double m, double n, double M, double l) {
	return cos(M) * exp(((fabs((m - n)) - l) - pow((M * ((0.5 * ((m + n) / M)) + -1.0)), 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_1 * ((0.5d0 * ((m + n) / m_1)) + (-1.0d0))) ** 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 * ((0.5 * ((m + n) / M)) + -1.0)), 2.0)));
}
def code(K, m, n, M, l):
	return math.cos(M) * math.exp(((math.fabs((m - n)) - l) - math.pow((M * ((0.5 * ((m + n) / M)) + -1.0)), 2.0)))
function code(K, m, n, M, l)
	return Float64(cos(M) * exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(M * Float64(Float64(0.5 * Float64(Float64(m + n) / M)) + -1.0)) ^ 2.0))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp(((abs((m - n)) - l) - ((M * ((0.5 * ((m + n) / M)) + -1.0)) ^ 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[(M * N[(N[(0.5 * N[(N[(m + n), $MachinePrecision] / M), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

Alternative 2: 86.1% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -5.1 \cdot 10^{+36}:\\
\;\;\;\;e^{{m}^{2} \cdot -0.25}\\

\mathbf{elif}\;m \leq -7 \cdot 10^{-44} \lor \neg \left(m \leq -1.15 \cdot 10^{-56}\right):\\
\;\;\;\;e^{\left(0.5 \cdot n - M\right) \cdot \left(\left(M - 0.5 \cdot n\right) - m\right) + \left(\left|m - n\right| - \ell\right)}\\

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


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

    1. Initial program 69.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 n around 0 58.1%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg72.7%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*90.4%

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

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

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

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified98.4%

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

    if -5.09999999999999973e36 < m < -6.9999999999999995e-44 or -1.15000000000000001e-56 < m

    1. Initial program 82.4%

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

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

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

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

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

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

      \[\leadsto 1 \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)} \]
    8. Step-by-step derivation
      1. +-commutative79.3%

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

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

        \[\leadsto 1 \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. *-commutative84.6%

        \[\leadsto 1 \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. *-commutative84.6%

        \[\leadsto 1 \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)} \]
    9. Simplified84.6%

      \[\leadsto 1 \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)} \]

    if -6.9999999999999995e-44 < m < -1.15000000000000001e-56

    1. Initial program 59.0%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 96.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ 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
 (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 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 = 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.exp(((Math.abs((m - n)) - l) - Math.pow((((m + n) / 2.0) - M), 2.0)));
}
def code(K, m, n, M, l):
	return math.exp(((math.fabs((m - n)) - l) - math.pow((((m + n) / 2.0) - M), 2.0)))
function code(K, m, n, M, l)
	return 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 = exp(((abs((m - n)) - l) - ((((m + n) / 2.0) - M) ^ 2.0)));
end
code[K_, m_, n_, M_, l_] := 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]
\begin{array}{l}

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

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

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

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

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

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

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

Alternative 4: 80.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{{m}^{2} \cdot -0.25}\\ t_1 := e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\ t_2 := e^{-{M}^{2}}\\ \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;M \leq -1.6 \cdot 10^{-9}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq -6.3 \cdot 10^{-49}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq -1.3 \cdot 10^{-73}:\\ \;\;\;\;\left(0.5 \cdot K\right) \cdot \left(\left(m \cdot e^{n \cdot \left(M - 0.5 \cdot m\right)}\right) \cdot \sin M\right)\\ \mathbf{elif}\;M \leq -7.2 \cdot 10^{-180}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 9.2 \cdot 10^{-10}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* (pow m 2.0) -0.25)))
        (t_1 (exp (- (- (fabs (- m n)) l) (* (* 0.5 m) (+ n (* 0.5 m))))))
        (t_2 (exp (- (pow M 2.0)))))
   (if (<= M -42000000.0)
     t_2
     (if (<= M -1.6e-9)
       t_0
       (if (<= M -6.3e-49)
         t_1
         (if (<= M -1.3e-73)
           (* (* 0.5 K) (* (* m (exp (* n (- M (* 0.5 m))))) (sin M)))
           (if (<= M -7.2e-180) t_0 (if (<= M 9.2e-10) t_1 t_2))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((pow(m, 2.0) * -0.25));
	double t_1 = exp(((fabs((m - n)) - l) - ((0.5 * m) * (n + (0.5 * m)))));
	double t_2 = exp(-pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_2;
	} else if (M <= -1.6e-9) {
		tmp = t_0;
	} else if (M <= -6.3e-49) {
		tmp = t_1;
	} else if (M <= -1.3e-73) {
		tmp = (0.5 * K) * ((m * exp((n * (M - (0.5 * m))))) * sin(M));
	} else if (M <= -7.2e-180) {
		tmp = t_0;
	} else if (M <= 9.2e-10) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = exp(((m ** 2.0d0) * (-0.25d0)))
    t_1 = exp(((abs((m - n)) - l) - ((0.5d0 * m) * (n + (0.5d0 * m)))))
    t_2 = exp(-(m_1 ** 2.0d0))
    if (m_1 <= (-42000000.0d0)) then
        tmp = t_2
    else if (m_1 <= (-1.6d-9)) then
        tmp = t_0
    else if (m_1 <= (-6.3d-49)) then
        tmp = t_1
    else if (m_1 <= (-1.3d-73)) then
        tmp = (0.5d0 * k) * ((m * exp((n * (m_1 - (0.5d0 * m))))) * sin(m_1))
    else if (m_1 <= (-7.2d-180)) then
        tmp = t_0
    else if (m_1 <= 9.2d-10) then
        tmp = t_1
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((Math.pow(m, 2.0) * -0.25));
	double t_1 = Math.exp(((Math.abs((m - n)) - l) - ((0.5 * m) * (n + (0.5 * m)))));
	double t_2 = Math.exp(-Math.pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_2;
	} else if (M <= -1.6e-9) {
		tmp = t_0;
	} else if (M <= -6.3e-49) {
		tmp = t_1;
	} else if (M <= -1.3e-73) {
		tmp = (0.5 * K) * ((m * Math.exp((n * (M - (0.5 * m))))) * Math.sin(M));
	} else if (M <= -7.2e-180) {
		tmp = t_0;
	} else if (M <= 9.2e-10) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((math.pow(m, 2.0) * -0.25))
	t_1 = math.exp(((math.fabs((m - n)) - l) - ((0.5 * m) * (n + (0.5 * m)))))
	t_2 = math.exp(-math.pow(M, 2.0))
	tmp = 0
	if M <= -42000000.0:
		tmp = t_2
	elif M <= -1.6e-9:
		tmp = t_0
	elif M <= -6.3e-49:
		tmp = t_1
	elif M <= -1.3e-73:
		tmp = (0.5 * K) * ((m * math.exp((n * (M - (0.5 * m))))) * math.sin(M))
	elif M <= -7.2e-180:
		tmp = t_0
	elif M <= 9.2e-10:
		tmp = t_1
	else:
		tmp = t_2
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64((m ^ 2.0) * -0.25))
	t_1 = exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(Float64(0.5 * m) * Float64(n + Float64(0.5 * m)))))
	t_2 = exp(Float64(-(M ^ 2.0)))
	tmp = 0.0
	if (M <= -42000000.0)
		tmp = t_2;
	elseif (M <= -1.6e-9)
		tmp = t_0;
	elseif (M <= -6.3e-49)
		tmp = t_1;
	elseif (M <= -1.3e-73)
		tmp = Float64(Float64(0.5 * K) * Float64(Float64(m * exp(Float64(n * Float64(M - Float64(0.5 * m))))) * sin(M)));
	elseif (M <= -7.2e-180)
		tmp = t_0;
	elseif (M <= 9.2e-10)
		tmp = t_1;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((m ^ 2.0) * -0.25));
	t_1 = exp(((abs((m - n)) - l) - ((0.5 * m) * (n + (0.5 * m)))));
	t_2 = exp(-(M ^ 2.0));
	tmp = 0.0;
	if (M <= -42000000.0)
		tmp = t_2;
	elseif (M <= -1.6e-9)
		tmp = t_0;
	elseif (M <= -6.3e-49)
		tmp = t_1;
	elseif (M <= -1.3e-73)
		tmp = (0.5 * K) * ((m * exp((n * (M - (0.5 * m))))) * sin(M));
	elseif (M <= -7.2e-180)
		tmp = t_0;
	elseif (M <= 9.2e-10)
		tmp = t_1;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(N[(0.5 * m), $MachinePrecision] * N[(n + N[(0.5 * m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]}, If[LessEqual[M, -42000000.0], t$95$2, If[LessEqual[M, -1.6e-9], t$95$0, If[LessEqual[M, -6.3e-49], t$95$1, If[LessEqual[M, -1.3e-73], N[(N[(0.5 * K), $MachinePrecision] * N[(N[(m * N[Exp[N[(n * N[(M - N[(0.5 * m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[M], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[M, -7.2e-180], t$95$0, If[LessEqual[M, 9.2e-10], t$95$1, t$95$2]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;M \leq -1.6 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -6.3 \cdot 10^{-49}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;M \leq -7.2 \cdot 10^{-180}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 9.2 \cdot 10^{-10}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if M < -4.2e7 or 9.20000000000000028e-10 < M

    1. Initial program 77.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.8%

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

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

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

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

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

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

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

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

    if -4.2e7 < M < -1.60000000000000006e-9 or -1.3e-73 < M < -7.1999999999999998e-180

    1. Initial program 64.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg64.3%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*80.3%

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative84.4%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified84.4%

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

    if -1.60000000000000006e-9 < M < -6.2999999999999997e-49 or -7.1999999999999998e-180 < M < 9.20000000000000028e-10

    1. Initial program 86.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.4%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*69.4%

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

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

    if -6.2999999999999997e-49 < M < -1.3e-73

    1. Initial program 77.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 n around 0 77.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg88.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq -1.6 \cdot 10^{-9}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq -6.3 \cdot 10^{-49}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\ \mathbf{elif}\;M \leq -1.3 \cdot 10^{-73}:\\ \;\;\;\;\left(0.5 \cdot K\right) \cdot \left(\left(m \cdot e^{n \cdot \left(M - 0.5 \cdot m\right)}\right) \cdot \sin M\right)\\ \mathbf{elif}\;M \leq -7.2 \cdot 10^{-180}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq 9.2 \cdot 10^{-10}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-{M}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 80.8% accurate, 1.8× speedup?

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

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

\mathbf{elif}\;M \leq -1 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -8.5 \cdot 10^{-47}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;M \leq -4.1 \cdot 10^{-180}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 9.2 \cdot 10^{-10}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -4.2e7 or 9.20000000000000028e-10 < M

    1. Initial program 77.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.8%

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

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

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

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

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

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

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

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

    if -4.2e7 < M < -1.00000000000000006e-9 or -8.4999999999999999e-47 < M < -4.1e-180

    1. Initial program 69.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 n around 0 54.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg68.8%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*77.4%

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative77.7%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified77.7%

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

    if -1.00000000000000006e-9 < M < -8.4999999999999999e-47 or -4.1e-180 < M < 9.20000000000000028e-10

    1. Initial program 86.3%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg70.2%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*70.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq -1 \cdot 10^{-9}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq -8.5 \cdot 10^{-47}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\ \mathbf{elif}\;M \leq -4.1 \cdot 10^{-180}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq 9.2 \cdot 10^{-10}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-{M}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 74.9% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{{m}^{2} \cdot -0.25}\\ t_1 := e^{-{M}^{2}}\\ \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq -1.45 \cdot 10^{-134}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq -6.5 \cdot 10^{-157}:\\ \;\;\;\;e^{{M}^{2} \cdot \left(\left(\frac{m}{M} + \frac{n}{M}\right) + -1\right)}\\ \mathbf{elif}\;M \leq -8.5 \cdot 10^{-237}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 1.55 \cdot 10^{-295}:\\ \;\;\;\;\cos \left(\left(0.5 \cdot n\right) \cdot K\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 2.3 \cdot 10^{-11}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* (pow m 2.0) -0.25))) (t_1 (exp (- (pow M 2.0)))))
   (if (<= M -42000000.0)
     t_1
     (if (<= M -1.45e-134)
       t_0
       (if (<= M -6.5e-157)
         (exp (* (pow M 2.0) (+ (+ (/ m M) (/ n M)) -1.0)))
         (if (<= M -8.5e-237)
           t_0
           (if (<= M 1.55e-295)
             (* (cos (* (* 0.5 n) K)) (exp (- l)))
             (if (<= M 2.3e-11) t_0 t_1))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((pow(m, 2.0) * -0.25));
	double t_1 = exp(-pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_1;
	} else if (M <= -1.45e-134) {
		tmp = t_0;
	} else if (M <= -6.5e-157) {
		tmp = exp((pow(M, 2.0) * (((m / M) + (n / M)) + -1.0)));
	} else if (M <= -8.5e-237) {
		tmp = t_0;
	} else if (M <= 1.55e-295) {
		tmp = cos(((0.5 * n) * K)) * exp(-l);
	} else if (M <= 2.3e-11) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 ** 2.0d0) * (-0.25d0)))
    t_1 = exp(-(m_1 ** 2.0d0))
    if (m_1 <= (-42000000.0d0)) then
        tmp = t_1
    else if (m_1 <= (-1.45d-134)) then
        tmp = t_0
    else if (m_1 <= (-6.5d-157)) then
        tmp = exp(((m_1 ** 2.0d0) * (((m / m_1) + (n / m_1)) + (-1.0d0))))
    else if (m_1 <= (-8.5d-237)) then
        tmp = t_0
    else if (m_1 <= 1.55d-295) then
        tmp = cos(((0.5d0 * n) * k)) * exp(-l)
    else if (m_1 <= 2.3d-11) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((Math.pow(m, 2.0) * -0.25));
	double t_1 = Math.exp(-Math.pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_1;
	} else if (M <= -1.45e-134) {
		tmp = t_0;
	} else if (M <= -6.5e-157) {
		tmp = Math.exp((Math.pow(M, 2.0) * (((m / M) + (n / M)) + -1.0)));
	} else if (M <= -8.5e-237) {
		tmp = t_0;
	} else if (M <= 1.55e-295) {
		tmp = Math.cos(((0.5 * n) * K)) * Math.exp(-l);
	} else if (M <= 2.3e-11) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((math.pow(m, 2.0) * -0.25))
	t_1 = math.exp(-math.pow(M, 2.0))
	tmp = 0
	if M <= -42000000.0:
		tmp = t_1
	elif M <= -1.45e-134:
		tmp = t_0
	elif M <= -6.5e-157:
		tmp = math.exp((math.pow(M, 2.0) * (((m / M) + (n / M)) + -1.0)))
	elif M <= -8.5e-237:
		tmp = t_0
	elif M <= 1.55e-295:
		tmp = math.cos(((0.5 * n) * K)) * math.exp(-l)
	elif M <= 2.3e-11:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64((m ^ 2.0) * -0.25))
	t_1 = exp(Float64(-(M ^ 2.0)))
	tmp = 0.0
	if (M <= -42000000.0)
		tmp = t_1;
	elseif (M <= -1.45e-134)
		tmp = t_0;
	elseif (M <= -6.5e-157)
		tmp = exp(Float64((M ^ 2.0) * Float64(Float64(Float64(m / M) + Float64(n / M)) + -1.0)));
	elseif (M <= -8.5e-237)
		tmp = t_0;
	elseif (M <= 1.55e-295)
		tmp = Float64(cos(Float64(Float64(0.5 * n) * K)) * exp(Float64(-l)));
	elseif (M <= 2.3e-11)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((m ^ 2.0) * -0.25));
	t_1 = exp(-(M ^ 2.0));
	tmp = 0.0;
	if (M <= -42000000.0)
		tmp = t_1;
	elseif (M <= -1.45e-134)
		tmp = t_0;
	elseif (M <= -6.5e-157)
		tmp = exp(((M ^ 2.0) * (((m / M) + (n / M)) + -1.0)));
	elseif (M <= -8.5e-237)
		tmp = t_0;
	elseif (M <= 1.55e-295)
		tmp = cos(((0.5 * n) * K)) * exp(-l);
	elseif (M <= 2.3e-11)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]}, If[LessEqual[M, -42000000.0], t$95$1, If[LessEqual[M, -1.45e-134], t$95$0, If[LessEqual[M, -6.5e-157], N[Exp[N[(N[Power[M, 2.0], $MachinePrecision] * N[(N[(N[(m / M), $MachinePrecision] + N[(n / M), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[M, -8.5e-237], t$95$0, If[LessEqual[M, 1.55e-295], N[(N[Cos[N[(N[(0.5 * n), $MachinePrecision] * K), $MachinePrecision]], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 2.3e-11], t$95$0, t$95$1]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{{m}^{2} \cdot -0.25}\\
t_1 := e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -42000000:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;M \leq -1.45 \cdot 10^{-134}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -6.5 \cdot 10^{-157}:\\
\;\;\;\;e^{{M}^{2} \cdot \left(\left(\frac{m}{M} + \frac{n}{M}\right) + -1\right)}\\

\mathbf{elif}\;M \leq -8.5 \cdot 10^{-237}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 1.55 \cdot 10^{-295}:\\
\;\;\;\;\cos \left(\left(0.5 \cdot n\right) \cdot K\right) \cdot e^{-\ell}\\

\mathbf{elif}\;M \leq 2.3 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if M < -4.2e7 or 2.30000000000000014e-11 < M

    1. Initial program 76.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 n around 0 64.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.3%

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

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

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

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

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

      \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    11. Step-by-step derivation
      1. mul-1-neg76.5%

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

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

    if -4.2e7 < M < -1.44999999999999997e-134 or -6.5000000000000002e-157 < M < -8.49999999999999951e-237 or 1.5500000000000001e-295 < M < 2.30000000000000014e-11

    1. Initial program 81.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.8%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*71.8%

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

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

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

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified64.3%

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

    if -1.44999999999999997e-134 < M < -6.5000000000000002e-157

    1. Initial program 74.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg57.8%

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

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

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

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

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

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

    if -8.49999999999999951e-237 < M < 1.5500000000000001e-295

    1. Initial program 88.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 n around 0 81.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \color{blue}{\left(\left(K \cdot n\right) \cdot 0.5\right)} \cdot e^{-\ell} \]
      2. associate-*l*68.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq -1.45 \cdot 10^{-134}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq -6.5 \cdot 10^{-157}:\\ \;\;\;\;e^{{M}^{2} \cdot \left(\left(\frac{m}{M} + \frac{n}{M}\right) + -1\right)}\\ \mathbf{elif}\;M \leq -8.5 \cdot 10^{-237}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq 1.55 \cdot 10^{-295}:\\ \;\;\;\;\cos \left(\left(0.5 \cdot n\right) \cdot K\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 2.3 \cdot 10^{-11}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;e^{-{M}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 71.4% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := e^{{m}^{2} \cdot -0.25}\\
\mathbf{if}\;\ell \leq -720:\\
\;\;\;\;e^{\ell}\\

\mathbf{elif}\;\ell \leq -8.5 \cdot 10^{-47}:\\
\;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\

\mathbf{elif}\;\ell \leq -3.2 \cdot 10^{-152}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -8 \cdot 10^{-183}:\\
\;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\

\mathbf{elif}\;\ell \leq 0.000112:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


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

    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 n around 0 63.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. *-commutative10.0%

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

      \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
    12. Step-by-step derivation
      1. pow110.0%

        \[\leadsto \color{blue}{{\left(e^{-\ell} \cdot \cos M\right)}^{1}} \]
      2. add-sqr-sqrt10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}} \cdot \cos M\right)}^{1} \]
      3. sqrt-unprod10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}} \cdot \cos M\right)}^{1} \]
      4. sqr-neg10.0%

        \[\leadsto {\left(e^{\sqrt{\color{blue}{\ell \cdot \ell}}} \cdot \cos M\right)}^{1} \]
      5. sqrt-unprod0.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}} \cdot \cos M\right)}^{1} \]
      6. add-sqr-sqrt81.0%

        \[\leadsto {\left(e^{\color{blue}{\ell}} \cdot \cos M\right)}^{1} \]
    13. Applied egg-rr81.0%

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

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

        \[\leadsto e^{\ell} \cdot \color{blue}{\cos \left(-M\right)} \]
      3. *-commutative81.0%

        \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\ell}} \]
      4. cos-neg81.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\ell} \]
    15. Simplified81.0%

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

      \[\leadsto \color{blue}{e^{\ell}} \]

    if -720 < l < -8.4999999999999999e-47

    1. Initial program 70.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg30.6%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*60.6%

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

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

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

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right) \cdot n}} \]
      2. metadata-eval70.6%

        \[\leadsto e^{\left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n} \]
      3. distribute-lft-neg-in70.6%

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right)} \cdot n} \]
      4. distribute-lft-neg-out70.6%

        \[\leadsto e^{\color{blue}{-\left(0.5 \cdot m\right) \cdot n}} \]
      5. *-commutative70.6%

        \[\leadsto e^{-\color{blue}{n \cdot \left(0.5 \cdot m\right)}} \]
      6. distribute-rgt-neg-out70.6%

        \[\leadsto e^{\color{blue}{n \cdot \left(-0.5 \cdot m\right)}} \]
      7. distribute-lft-neg-in70.6%

        \[\leadsto e^{n \cdot \color{blue}{\left(\left(-0.5\right) \cdot m\right)}} \]
      8. metadata-eval70.6%

        \[\leadsto e^{n \cdot \left(\color{blue}{-0.5} \cdot m\right)} \]
    14. Simplified70.6%

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

    if -8.4999999999999999e-47 < l < -3.20000000000000013e-152 or -8.00000000000000004e-183 < l < 1.11999999999999998e-4

    1. Initial program 82.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 n around 0 62.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.7%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*54.5%

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative60.9%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified60.9%

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

    if -3.20000000000000013e-152 < l < -8.00000000000000004e-183

    1. Initial program 50.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg66.9%

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

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

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

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

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

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

    if 1.11999999999999998e-4 < l

    1. Initial program 79.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg74.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    13. Step-by-step derivation
      1. mul-1-neg98.6%

        \[\leadsto e^{\color{blue}{-\ell}} \]
    14. Simplified98.6%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification75.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -720:\\ \;\;\;\;e^{\ell}\\ \mathbf{elif}\;\ell \leq -8.5 \cdot 10^{-47}:\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq -3.2 \cdot 10^{-152}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;\ell \leq -8 \cdot 10^{-183}:\\ \;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ \mathbf{elif}\;\ell \leq 0.000112:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 75.8% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{{m}^{2} \cdot -0.25}\\ t_1 := e^{-{M}^{2}}\\ \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq -6.8 \cdot 10^{-204}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq -4.4 \cdot 10^{-258}:\\ \;\;\;\;\cos \left(\left(0.5 \cdot n\right) \cdot K\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 2.3 \cdot 10^{-11}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* (pow m 2.0) -0.25))) (t_1 (exp (- (pow M 2.0)))))
   (if (<= M -42000000.0)
     t_1
     (if (<= M -6.8e-204)
       t_0
       (if (<= M -4.4e-258)
         (* (cos (* (* 0.5 n) K)) (exp (- l)))
         (if (<= M 2.3e-11) t_0 t_1))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((pow(m, 2.0) * -0.25));
	double t_1 = exp(-pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_1;
	} else if (M <= -6.8e-204) {
		tmp = t_0;
	} else if (M <= -4.4e-258) {
		tmp = cos(((0.5 * n) * K)) * exp(-l);
	} else if (M <= 2.3e-11) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 ** 2.0d0) * (-0.25d0)))
    t_1 = exp(-(m_1 ** 2.0d0))
    if (m_1 <= (-42000000.0d0)) then
        tmp = t_1
    else if (m_1 <= (-6.8d-204)) then
        tmp = t_0
    else if (m_1 <= (-4.4d-258)) then
        tmp = cos(((0.5d0 * n) * k)) * exp(-l)
    else if (m_1 <= 2.3d-11) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((Math.pow(m, 2.0) * -0.25));
	double t_1 = Math.exp(-Math.pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_1;
	} else if (M <= -6.8e-204) {
		tmp = t_0;
	} else if (M <= -4.4e-258) {
		tmp = Math.cos(((0.5 * n) * K)) * Math.exp(-l);
	} else if (M <= 2.3e-11) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((math.pow(m, 2.0) * -0.25))
	t_1 = math.exp(-math.pow(M, 2.0))
	tmp = 0
	if M <= -42000000.0:
		tmp = t_1
	elif M <= -6.8e-204:
		tmp = t_0
	elif M <= -4.4e-258:
		tmp = math.cos(((0.5 * n) * K)) * math.exp(-l)
	elif M <= 2.3e-11:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64((m ^ 2.0) * -0.25))
	t_1 = exp(Float64(-(M ^ 2.0)))
	tmp = 0.0
	if (M <= -42000000.0)
		tmp = t_1;
	elseif (M <= -6.8e-204)
		tmp = t_0;
	elseif (M <= -4.4e-258)
		tmp = Float64(cos(Float64(Float64(0.5 * n) * K)) * exp(Float64(-l)));
	elseif (M <= 2.3e-11)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((m ^ 2.0) * -0.25));
	t_1 = exp(-(M ^ 2.0));
	tmp = 0.0;
	if (M <= -42000000.0)
		tmp = t_1;
	elseif (M <= -6.8e-204)
		tmp = t_0;
	elseif (M <= -4.4e-258)
		tmp = cos(((0.5 * n) * K)) * exp(-l);
	elseif (M <= 2.3e-11)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]}, If[LessEqual[M, -42000000.0], t$95$1, If[LessEqual[M, -6.8e-204], t$95$0, If[LessEqual[M, -4.4e-258], N[(N[Cos[N[(N[(0.5 * n), $MachinePrecision] * K), $MachinePrecision]], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 2.3e-11], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{{m}^{2} \cdot -0.25}\\
t_1 := e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -42000000:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;M \leq -6.8 \cdot 10^{-204}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -4.4 \cdot 10^{-258}:\\
\;\;\;\;\cos \left(\left(0.5 \cdot n\right) \cdot K\right) \cdot e^{-\ell}\\

\mathbf{elif}\;M \leq 2.3 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -4.2e7 or 2.30000000000000014e-11 < M

    1. Initial program 76.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 n around 0 64.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.3%

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

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

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

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

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

      \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    11. Step-by-step derivation
      1. mul-1-neg76.5%

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

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

    if -4.2e7 < M < -6.8000000000000004e-204 or -4.40000000000000031e-258 < M < 2.30000000000000014e-11

    1. Initial program 81.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg68.9%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*70.8%

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative63.1%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified63.1%

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

    if -6.8000000000000004e-204 < M < -4.40000000000000031e-258

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \color{blue}{\left(\left(K \cdot n\right) \cdot 0.5\right)} \cdot e^{-\ell} \]
      2. associate-*l*59.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq -6.8 \cdot 10^{-204}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq -4.4 \cdot 10^{-258}:\\ \;\;\;\;\cos \left(\left(0.5 \cdot n\right) \cdot K\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 2.3 \cdot 10^{-11}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;e^{-{M}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 75.8% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{{m}^{2} \cdot -0.25}\\ t_1 := e^{-{M}^{2}}\\ \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq -6.8 \cdot 10^{-204}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq -5 \cdot 10^{-258}:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(K \cdot \left(0.5 \cdot m\right)\right)\\ \mathbf{elif}\;M \leq 9.2 \cdot 10^{-10}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* (pow m 2.0) -0.25))) (t_1 (exp (- (pow M 2.0)))))
   (if (<= M -42000000.0)
     t_1
     (if (<= M -6.8e-204)
       t_0
       (if (<= M -5e-258)
         (* (exp (- l)) (cos (* K (* 0.5 m))))
         (if (<= M 9.2e-10) t_0 t_1))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((pow(m, 2.0) * -0.25));
	double t_1 = exp(-pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_1;
	} else if (M <= -6.8e-204) {
		tmp = t_0;
	} else if (M <= -5e-258) {
		tmp = exp(-l) * cos((K * (0.5 * m)));
	} else if (M <= 9.2e-10) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 ** 2.0d0) * (-0.25d0)))
    t_1 = exp(-(m_1 ** 2.0d0))
    if (m_1 <= (-42000000.0d0)) then
        tmp = t_1
    else if (m_1 <= (-6.8d-204)) then
        tmp = t_0
    else if (m_1 <= (-5d-258)) then
        tmp = exp(-l) * cos((k * (0.5d0 * m)))
    else if (m_1 <= 9.2d-10) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((Math.pow(m, 2.0) * -0.25));
	double t_1 = Math.exp(-Math.pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_1;
	} else if (M <= -6.8e-204) {
		tmp = t_0;
	} else if (M <= -5e-258) {
		tmp = Math.exp(-l) * Math.cos((K * (0.5 * m)));
	} else if (M <= 9.2e-10) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((math.pow(m, 2.0) * -0.25))
	t_1 = math.exp(-math.pow(M, 2.0))
	tmp = 0
	if M <= -42000000.0:
		tmp = t_1
	elif M <= -6.8e-204:
		tmp = t_0
	elif M <= -5e-258:
		tmp = math.exp(-l) * math.cos((K * (0.5 * m)))
	elif M <= 9.2e-10:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64((m ^ 2.0) * -0.25))
	t_1 = exp(Float64(-(M ^ 2.0)))
	tmp = 0.0
	if (M <= -42000000.0)
		tmp = t_1;
	elseif (M <= -6.8e-204)
		tmp = t_0;
	elseif (M <= -5e-258)
		tmp = Float64(exp(Float64(-l)) * cos(Float64(K * Float64(0.5 * m))));
	elseif (M <= 9.2e-10)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((m ^ 2.0) * -0.25));
	t_1 = exp(-(M ^ 2.0));
	tmp = 0.0;
	if (M <= -42000000.0)
		tmp = t_1;
	elseif (M <= -6.8e-204)
		tmp = t_0;
	elseif (M <= -5e-258)
		tmp = exp(-l) * cos((K * (0.5 * m)));
	elseif (M <= 9.2e-10)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]}, If[LessEqual[M, -42000000.0], t$95$1, If[LessEqual[M, -6.8e-204], t$95$0, If[LessEqual[M, -5e-258], N[(N[Exp[(-l)], $MachinePrecision] * N[Cos[N[(K * N[(0.5 * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 9.2e-10], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{{m}^{2} \cdot -0.25}\\
t_1 := e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -42000000:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;M \leq -6.8 \cdot 10^{-204}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -5 \cdot 10^{-258}:\\
\;\;\;\;e^{-\ell} \cdot \cos \left(K \cdot \left(0.5 \cdot m\right)\right)\\

\mathbf{elif}\;M \leq 9.2 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -4.2e7 or 9.20000000000000028e-10 < M

    1. Initial program 77.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.8%

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

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

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

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

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

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

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

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

    if -4.2e7 < M < -6.8000000000000004e-204 or -4.9999999999999999e-258 < M < 9.20000000000000028e-10

    1. Initial program 80.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 n around 0 57.5%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg68.3%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*71.0%

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative63.4%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified63.4%

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

    if -6.8000000000000004e-204 < M < -4.9999999999999999e-258

    1. Initial program 91.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq -6.8 \cdot 10^{-204}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq -5 \cdot 10^{-258}:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(K \cdot \left(0.5 \cdot m\right)\right)\\ \mathbf{elif}\;M \leq 9.2 \cdot 10^{-10}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;e^{-{M}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 75.7% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{{m}^{2} \cdot -0.25}\\ t_1 := e^{-{M}^{2}}\\ \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq -6.5 \cdot 10^{-208}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq -8.5 \cdot 10^{-268}:\\ \;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\ \mathbf{elif}\;M \leq 0.0011:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* (pow m 2.0) -0.25))) (t_1 (exp (- (pow M 2.0)))))
   (if (<= M -42000000.0)
     t_1
     (if (<= M -6.5e-208)
       t_0
       (if (<= M -8.5e-268)
         (* K (* 0.5 (* m (sin M))))
         (if (<= M 0.0011) t_0 t_1))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((pow(m, 2.0) * -0.25));
	double t_1 = exp(-pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_1;
	} else if (M <= -6.5e-208) {
		tmp = t_0;
	} else if (M <= -8.5e-268) {
		tmp = K * (0.5 * (m * sin(M)));
	} else if (M <= 0.0011) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 ** 2.0d0) * (-0.25d0)))
    t_1 = exp(-(m_1 ** 2.0d0))
    if (m_1 <= (-42000000.0d0)) then
        tmp = t_1
    else if (m_1 <= (-6.5d-208)) then
        tmp = t_0
    else if (m_1 <= (-8.5d-268)) then
        tmp = k * (0.5d0 * (m * sin(m_1)))
    else if (m_1 <= 0.0011d0) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((Math.pow(m, 2.0) * -0.25));
	double t_1 = Math.exp(-Math.pow(M, 2.0));
	double tmp;
	if (M <= -42000000.0) {
		tmp = t_1;
	} else if (M <= -6.5e-208) {
		tmp = t_0;
	} else if (M <= -8.5e-268) {
		tmp = K * (0.5 * (m * Math.sin(M)));
	} else if (M <= 0.0011) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((math.pow(m, 2.0) * -0.25))
	t_1 = math.exp(-math.pow(M, 2.0))
	tmp = 0
	if M <= -42000000.0:
		tmp = t_1
	elif M <= -6.5e-208:
		tmp = t_0
	elif M <= -8.5e-268:
		tmp = K * (0.5 * (m * math.sin(M)))
	elif M <= 0.0011:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64((m ^ 2.0) * -0.25))
	t_1 = exp(Float64(-(M ^ 2.0)))
	tmp = 0.0
	if (M <= -42000000.0)
		tmp = t_1;
	elseif (M <= -6.5e-208)
		tmp = t_0;
	elseif (M <= -8.5e-268)
		tmp = Float64(K * Float64(0.5 * Float64(m * sin(M))));
	elseif (M <= 0.0011)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((m ^ 2.0) * -0.25));
	t_1 = exp(-(M ^ 2.0));
	tmp = 0.0;
	if (M <= -42000000.0)
		tmp = t_1;
	elseif (M <= -6.5e-208)
		tmp = t_0;
	elseif (M <= -8.5e-268)
		tmp = K * (0.5 * (m * sin(M)));
	elseif (M <= 0.0011)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]}, If[LessEqual[M, -42000000.0], t$95$1, If[LessEqual[M, -6.5e-208], t$95$0, If[LessEqual[M, -8.5e-268], N[(K * N[(0.5 * N[(m * N[Sin[M], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 0.0011], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{{m}^{2} \cdot -0.25}\\
t_1 := e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -42000000:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;M \leq -6.5 \cdot 10^{-208}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -8.5 \cdot 10^{-268}:\\
\;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\

\mathbf{elif}\;M \leq 0.0011:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -4.2e7 or 0.00110000000000000007 < M

    1. Initial program 77.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 n around 0 65.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg70.4%

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

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

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

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

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

      \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    11. Step-by-step derivation
      1. mul-1-neg77.6%

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

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

    if -4.2e7 < M < -6.4999999999999998e-208 or -8.50000000000000052e-268 < M < 0.00110000000000000007

    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 n around 0 56.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg67.4%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*71.0%

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative63.4%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified63.4%

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

    if -6.4999999999999998e-208 < M < -8.50000000000000052e-268

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
    11. Taylor expanded in K around 0 9.9%

      \[\leadsto \color{blue}{\cos \left(-M\right)} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    12. Step-by-step derivation
      1. cos-neg9.9%

        \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    13. Simplified9.9%

      \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    14. Taylor expanded in K around 0 10.2%

      \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
    15. Step-by-step derivation
      1. associate-*r*10.2%

        \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(-M\right)\right)} \]
      2. sin-neg10.2%

        \[\leadsto \cos M + -0.5 \cdot \left(\left(K \cdot m\right) \cdot \color{blue}{\left(-\sin M\right)}\right) \]
    16. Simplified10.2%

      \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \left(-\sin M\right)\right)} \]
    17. Taylor expanded in K around inf 47.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)} \]
    18. Step-by-step derivation
      1. associate-*r*47.5%

        \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(m \cdot \sin M\right)} \]
      2. *-commutative47.5%

        \[\leadsto \color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m \cdot \sin M\right) \]
      3. associate-*l*47.5%

        \[\leadsto \color{blue}{K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)} \]
    19. Simplified47.5%

      \[\leadsto \color{blue}{K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification81.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -42000000:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{elif}\;M \leq -6.5 \cdot 10^{-208}:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;M \leq -8.5 \cdot 10^{-268}:\\ \;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\ \mathbf{elif}\;M \leq 0.0011:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;e^{-{M}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 85.3% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -2.6 \cdot 10^{+127}:\\
\;\;\;\;e^{{m}^{2} \cdot -0.25}\\

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


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

    1. Initial program 64.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 n around 0 52.4%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg71.5%

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified100.0%

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

    if -2.6000000000000002e127 < m

    1. Initial program 82.0%

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

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

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

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

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

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

      \[\leadsto 1 \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)} \]
    8. Step-by-step derivation
      1. +-commutative77.3%

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

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

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

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

        \[\leadsto 1 \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)} \]
    9. Simplified82.9%

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

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

Alternative 12: 80.4% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 70.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 n around 0 57.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg70.6%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*90.3%

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

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

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

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified98.6%

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

    if -54 < m

    1. Initial program 82.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 n around 0 64.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg69.5%

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

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

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

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

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

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

Alternative 13: 61.7% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ t_1 := e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{if}\;\ell \leq -720:\\ \;\;\;\;e^{\ell}\\ \mathbf{elif}\;\ell \leq -8.6 \cdot 10^{-51}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -3.9 \cdot 10^{-84}:\\ \;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\ \mathbf{elif}\;\ell \leq -3.3 \cdot 10^{-93}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-169}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -9 \cdot 10^{-218}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 3.35 \cdot 10^{-301}:\\ \;\;\;\;\left(K \cdot -0.5\right) \cdot \left(m \cdot \sin \left(n \cdot \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.8 \cdot 10^{-15}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* n (- M (* 0.5 m))))) (t_1 (exp (* n (* m -0.5)))))
   (if (<= l -720.0)
     (exp l)
     (if (<= l -8.6e-51)
       t_1
       (if (<= l -3.9e-84)
         (* K (* 0.5 (* m (sin M))))
         (if (<= l -3.3e-93)
           t_0
           (if (<= l -2e-169)
             t_1
             (if (<= l -9e-218)
               t_0
               (if (<= l 3.35e-301)
                 (* (* K -0.5) (* m (sin (* n (* 0.5 K)))))
                 (if (<= l 5.8e-15) t_0 (exp (- l))))))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((n * (M - (0.5 * m))));
	double t_1 = exp((n * (m * -0.5)));
	double tmp;
	if (l <= -720.0) {
		tmp = exp(l);
	} else if (l <= -8.6e-51) {
		tmp = t_1;
	} else if (l <= -3.9e-84) {
		tmp = K * (0.5 * (m * sin(M)));
	} else if (l <= -3.3e-93) {
		tmp = t_0;
	} else if (l <= -2e-169) {
		tmp = t_1;
	} else if (l <= -9e-218) {
		tmp = t_0;
	} else if (l <= 3.35e-301) {
		tmp = (K * -0.5) * (m * sin((n * (0.5 * K))));
	} else if (l <= 5.8e-15) {
		tmp = t_0;
	} else {
		tmp = exp(-l);
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp((n * (m_1 - (0.5d0 * m))))
    t_1 = exp((n * (m * (-0.5d0))))
    if (l <= (-720.0d0)) then
        tmp = exp(l)
    else if (l <= (-8.6d-51)) then
        tmp = t_1
    else if (l <= (-3.9d-84)) then
        tmp = k * (0.5d0 * (m * sin(m_1)))
    else if (l <= (-3.3d-93)) then
        tmp = t_0
    else if (l <= (-2d-169)) then
        tmp = t_1
    else if (l <= (-9d-218)) then
        tmp = t_0
    else if (l <= 3.35d-301) then
        tmp = (k * (-0.5d0)) * (m * sin((n * (0.5d0 * k))))
    else if (l <= 5.8d-15) then
        tmp = t_0
    else
        tmp = exp(-l)
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((n * (M - (0.5 * m))));
	double t_1 = Math.exp((n * (m * -0.5)));
	double tmp;
	if (l <= -720.0) {
		tmp = Math.exp(l);
	} else if (l <= -8.6e-51) {
		tmp = t_1;
	} else if (l <= -3.9e-84) {
		tmp = K * (0.5 * (m * Math.sin(M)));
	} else if (l <= -3.3e-93) {
		tmp = t_0;
	} else if (l <= -2e-169) {
		tmp = t_1;
	} else if (l <= -9e-218) {
		tmp = t_0;
	} else if (l <= 3.35e-301) {
		tmp = (K * -0.5) * (m * Math.sin((n * (0.5 * K))));
	} else if (l <= 5.8e-15) {
		tmp = t_0;
	} else {
		tmp = Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((n * (M - (0.5 * m))))
	t_1 = math.exp((n * (m * -0.5)))
	tmp = 0
	if l <= -720.0:
		tmp = math.exp(l)
	elif l <= -8.6e-51:
		tmp = t_1
	elif l <= -3.9e-84:
		tmp = K * (0.5 * (m * math.sin(M)))
	elif l <= -3.3e-93:
		tmp = t_0
	elif l <= -2e-169:
		tmp = t_1
	elif l <= -9e-218:
		tmp = t_0
	elif l <= 3.35e-301:
		tmp = (K * -0.5) * (m * math.sin((n * (0.5 * K))))
	elif l <= 5.8e-15:
		tmp = t_0
	else:
		tmp = math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(n * Float64(M - Float64(0.5 * m))))
	t_1 = exp(Float64(n * Float64(m * -0.5)))
	tmp = 0.0
	if (l <= -720.0)
		tmp = exp(l);
	elseif (l <= -8.6e-51)
		tmp = t_1;
	elseif (l <= -3.9e-84)
		tmp = Float64(K * Float64(0.5 * Float64(m * sin(M))));
	elseif (l <= -3.3e-93)
		tmp = t_0;
	elseif (l <= -2e-169)
		tmp = t_1;
	elseif (l <= -9e-218)
		tmp = t_0;
	elseif (l <= 3.35e-301)
		tmp = Float64(Float64(K * -0.5) * Float64(m * sin(Float64(n * Float64(0.5 * K)))));
	elseif (l <= 5.8e-15)
		tmp = t_0;
	else
		tmp = exp(Float64(-l));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp((n * (M - (0.5 * m))));
	t_1 = exp((n * (m * -0.5)));
	tmp = 0.0;
	if (l <= -720.0)
		tmp = exp(l);
	elseif (l <= -8.6e-51)
		tmp = t_1;
	elseif (l <= -3.9e-84)
		tmp = K * (0.5 * (m * sin(M)));
	elseif (l <= -3.3e-93)
		tmp = t_0;
	elseif (l <= -2e-169)
		tmp = t_1;
	elseif (l <= -9e-218)
		tmp = t_0;
	elseif (l <= 3.35e-301)
		tmp = (K * -0.5) * (m * sin((n * (0.5 * K))));
	elseif (l <= 5.8e-15)
		tmp = t_0;
	else
		tmp = exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(n * N[(M - N[(0.5 * m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(n * N[(m * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -720.0], N[Exp[l], $MachinePrecision], If[LessEqual[l, -8.6e-51], t$95$1, If[LessEqual[l, -3.9e-84], N[(K * N[(0.5 * N[(m * N[Sin[M], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -3.3e-93], t$95$0, If[LessEqual[l, -2e-169], t$95$1, If[LessEqual[l, -9e-218], t$95$0, If[LessEqual[l, 3.35e-301], N[(N[(K * -0.5), $MachinePrecision] * N[(m * N[Sin[N[(n * N[(0.5 * K), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.8e-15], t$95$0, N[Exp[(-l)], $MachinePrecision]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{n \cdot \left(M - 0.5 \cdot m\right)}\\
t_1 := e^{n \cdot \left(m \cdot -0.5\right)}\\
\mathbf{if}\;\ell \leq -720:\\
\;\;\;\;e^{\ell}\\

\mathbf{elif}\;\ell \leq -8.6 \cdot 10^{-51}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -3.9 \cdot 10^{-84}:\\
\;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\

\mathbf{elif}\;\ell \leq -3.3 \cdot 10^{-93}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-169}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -9 \cdot 10^{-218}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 3.35 \cdot 10^{-301}:\\
\;\;\;\;\left(K \cdot -0.5\right) \cdot \left(m \cdot \sin \left(n \cdot \left(0.5 \cdot K\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 5.8 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


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

    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 n around 0 63.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. *-commutative10.0%

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

      \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
    12. Step-by-step derivation
      1. pow110.0%

        \[\leadsto \color{blue}{{\left(e^{-\ell} \cdot \cos M\right)}^{1}} \]
      2. add-sqr-sqrt10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}} \cdot \cos M\right)}^{1} \]
      3. sqrt-unprod10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}} \cdot \cos M\right)}^{1} \]
      4. sqr-neg10.0%

        \[\leadsto {\left(e^{\sqrt{\color{blue}{\ell \cdot \ell}}} \cdot \cos M\right)}^{1} \]
      5. sqrt-unprod0.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}} \cdot \cos M\right)}^{1} \]
      6. add-sqr-sqrt81.0%

        \[\leadsto {\left(e^{\color{blue}{\ell}} \cdot \cos M\right)}^{1} \]
    13. Applied egg-rr81.0%

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

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

        \[\leadsto e^{\ell} \cdot \color{blue}{\cos \left(-M\right)} \]
      3. *-commutative81.0%

        \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\ell}} \]
      4. cos-neg81.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\ell} \]
    15. Simplified81.0%

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

      \[\leadsto \color{blue}{e^{\ell}} \]

    if -720 < l < -8.5999999999999995e-51 or -3.3000000000000001e-93 < l < -2.00000000000000004e-169

    1. Initial program 73.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg42.7%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*63.8%

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

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

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

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right) \cdot n}} \]
      2. metadata-eval69.2%

        \[\leadsto e^{\left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n} \]
      3. distribute-lft-neg-in69.2%

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right)} \cdot n} \]
      4. distribute-lft-neg-out69.2%

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

        \[\leadsto e^{-\color{blue}{n \cdot \left(0.5 \cdot m\right)}} \]
      6. distribute-rgt-neg-out69.2%

        \[\leadsto e^{\color{blue}{n \cdot \left(-0.5 \cdot m\right)}} \]
      7. distribute-lft-neg-in69.2%

        \[\leadsto e^{n \cdot \color{blue}{\left(\left(-0.5\right) \cdot m\right)}} \]
      8. metadata-eval69.2%

        \[\leadsto e^{n \cdot \left(\color{blue}{-0.5} \cdot m\right)} \]
    14. Simplified69.2%

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

    if -8.5999999999999995e-51 < l < -3.90000000000000023e-84

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
    11. Taylor expanded in K around 0 9.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    12. Step-by-step derivation
      1. cos-neg9.1%

        \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    13. Simplified9.1%

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

      \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
    15. Step-by-step derivation
      1. associate-*r*9.2%

        \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(-M\right)\right)} \]
      2. sin-neg9.2%

        \[\leadsto \cos M + -0.5 \cdot \left(\left(K \cdot m\right) \cdot \color{blue}{\left(-\sin M\right)}\right) \]
    16. Simplified9.2%

      \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \left(-\sin M\right)\right)} \]
    17. Taylor expanded in K around inf 29.1%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)} \]
    18. Step-by-step derivation
      1. associate-*r*29.1%

        \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(m \cdot \sin M\right)} \]
      2. *-commutative29.1%

        \[\leadsto \color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m \cdot \sin M\right) \]
      3. associate-*l*29.1%

        \[\leadsto \color{blue}{K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)} \]
    19. Simplified29.1%

      \[\leadsto \color{blue}{K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)} \]

    if -3.90000000000000023e-84 < l < -3.3000000000000001e-93 or -2.00000000000000004e-169 < l < -8.99999999999999953e-218 or 3.35000000000000011e-301 < l < 5.80000000000000037e-15

    1. Initial program 82.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg71.8%

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

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

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

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

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

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

    if -8.99999999999999953e-218 < l < 3.35000000000000011e-301

    1. Initial program 67.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
    11. Taylor expanded in K around 0 2.4%

      \[\leadsto \color{blue}{\cos \left(-M\right)} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    12. Step-by-step derivation
      1. cos-neg2.4%

        \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    13. Simplified2.4%

      \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    14. Taylor expanded in K around inf 16.6%

      \[\leadsto \color{blue}{-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
    15. Step-by-step derivation
      1. associate-*r*16.6%

        \[\leadsto \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)} \]
      2. associate-*r*16.6%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(\color{blue}{\left(0.5 \cdot K\right) \cdot n} - M\right)\right) \]
      3. *-commutative16.6%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot n - M\right)\right) \]
      4. *-commutative16.6%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(\color{blue}{n \cdot \left(K \cdot 0.5\right)} - M\right)\right) \]
      5. *-commutative16.6%

        \[\leadsto \color{blue}{\left(K \cdot -0.5\right)} \cdot \left(m \cdot \sin \left(n \cdot \left(K \cdot 0.5\right) - M\right)\right) \]
    16. Simplified16.6%

      \[\leadsto \color{blue}{\left(K \cdot -0.5\right) \cdot \left(m \cdot \sin \left(n \cdot \left(K \cdot 0.5\right) - M\right)\right)} \]
    17. Taylor expanded in M around 0 30.8%

      \[\leadsto \left(K \cdot -0.5\right) \cdot \left(m \cdot \color{blue}{\sin \left(0.5 \cdot \left(K \cdot n\right)\right)}\right) \]
    18. Step-by-step derivation
      1. associate-*r*30.8%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(m \cdot \sin \color{blue}{\left(\left(0.5 \cdot K\right) \cdot n\right)}\right) \]
      2. *-commutative30.8%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(m \cdot \sin \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot n\right)\right) \]
      3. *-commutative30.8%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(m \cdot \sin \color{blue}{\left(n \cdot \left(K \cdot 0.5\right)\right)}\right) \]
    19. Simplified30.8%

      \[\leadsto \left(K \cdot -0.5\right) \cdot \left(m \cdot \color{blue}{\sin \left(n \cdot \left(K \cdot 0.5\right)\right)}\right) \]

    if 5.80000000000000037e-15 < l

    1. Initial program 81.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 n around 0 69.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg75.9%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*82.7%

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

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

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    13. Step-by-step derivation
      1. mul-1-neg92.1%

        \[\leadsto e^{\color{blue}{-\ell}} \]
    14. Simplified92.1%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  3. Recombined 6 regimes into one program.
  4. Final simplification66.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -720:\\ \;\;\;\;e^{\ell}\\ \mathbf{elif}\;\ell \leq -8.6 \cdot 10^{-51}:\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq -3.9 \cdot 10^{-84}:\\ \;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\ \mathbf{elif}\;\ell \leq -3.3 \cdot 10^{-93}:\\ \;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-169}:\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq -9 \cdot 10^{-218}:\\ \;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ \mathbf{elif}\;\ell \leq 3.35 \cdot 10^{-301}:\\ \;\;\;\;\left(K \cdot -0.5\right) \cdot \left(m \cdot \sin \left(n \cdot \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.8 \cdot 10^{-15}:\\ \;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 61.7% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ t_1 := e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{if}\;\ell \leq -720:\\ \;\;\;\;e^{\ell}\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{-48}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -3.3 \cdot 10^{-84}:\\ \;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\ \mathbf{elif}\;\ell \leq -1.45 \cdot 10^{-93}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-169}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -9 \cdot 10^{-218}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 4.6 \cdot 10^{-304}:\\ \;\;\;\;-0.5 \cdot \left(\sin \left(n \cdot \left(0.5 \cdot K\right)\right) \cdot \left(m \cdot K\right)\right)\\ \mathbf{elif}\;\ell \leq 5.8 \cdot 10^{-15}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* n (- M (* 0.5 m))))) (t_1 (exp (* n (* m -0.5)))))
   (if (<= l -720.0)
     (exp l)
     (if (<= l -1.5e-48)
       t_1
       (if (<= l -3.3e-84)
         (* K (* 0.5 (* m (sin M))))
         (if (<= l -1.45e-93)
           t_0
           (if (<= l -2e-169)
             t_1
             (if (<= l -9e-218)
               t_0
               (if (<= l 4.6e-304)
                 (* -0.5 (* (sin (* n (* 0.5 K))) (* m K)))
                 (if (<= l 5.8e-15) t_0 (exp (- l))))))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((n * (M - (0.5 * m))));
	double t_1 = exp((n * (m * -0.5)));
	double tmp;
	if (l <= -720.0) {
		tmp = exp(l);
	} else if (l <= -1.5e-48) {
		tmp = t_1;
	} else if (l <= -3.3e-84) {
		tmp = K * (0.5 * (m * sin(M)));
	} else if (l <= -1.45e-93) {
		tmp = t_0;
	} else if (l <= -2e-169) {
		tmp = t_1;
	} else if (l <= -9e-218) {
		tmp = t_0;
	} else if (l <= 4.6e-304) {
		tmp = -0.5 * (sin((n * (0.5 * K))) * (m * K));
	} else if (l <= 5.8e-15) {
		tmp = t_0;
	} else {
		tmp = exp(-l);
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp((n * (m_1 - (0.5d0 * m))))
    t_1 = exp((n * (m * (-0.5d0))))
    if (l <= (-720.0d0)) then
        tmp = exp(l)
    else if (l <= (-1.5d-48)) then
        tmp = t_1
    else if (l <= (-3.3d-84)) then
        tmp = k * (0.5d0 * (m * sin(m_1)))
    else if (l <= (-1.45d-93)) then
        tmp = t_0
    else if (l <= (-2d-169)) then
        tmp = t_1
    else if (l <= (-9d-218)) then
        tmp = t_0
    else if (l <= 4.6d-304) then
        tmp = (-0.5d0) * (sin((n * (0.5d0 * k))) * (m * k))
    else if (l <= 5.8d-15) then
        tmp = t_0
    else
        tmp = exp(-l)
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((n * (M - (0.5 * m))));
	double t_1 = Math.exp((n * (m * -0.5)));
	double tmp;
	if (l <= -720.0) {
		tmp = Math.exp(l);
	} else if (l <= -1.5e-48) {
		tmp = t_1;
	} else if (l <= -3.3e-84) {
		tmp = K * (0.5 * (m * Math.sin(M)));
	} else if (l <= -1.45e-93) {
		tmp = t_0;
	} else if (l <= -2e-169) {
		tmp = t_1;
	} else if (l <= -9e-218) {
		tmp = t_0;
	} else if (l <= 4.6e-304) {
		tmp = -0.5 * (Math.sin((n * (0.5 * K))) * (m * K));
	} else if (l <= 5.8e-15) {
		tmp = t_0;
	} else {
		tmp = Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((n * (M - (0.5 * m))))
	t_1 = math.exp((n * (m * -0.5)))
	tmp = 0
	if l <= -720.0:
		tmp = math.exp(l)
	elif l <= -1.5e-48:
		tmp = t_1
	elif l <= -3.3e-84:
		tmp = K * (0.5 * (m * math.sin(M)))
	elif l <= -1.45e-93:
		tmp = t_0
	elif l <= -2e-169:
		tmp = t_1
	elif l <= -9e-218:
		tmp = t_0
	elif l <= 4.6e-304:
		tmp = -0.5 * (math.sin((n * (0.5 * K))) * (m * K))
	elif l <= 5.8e-15:
		tmp = t_0
	else:
		tmp = math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(n * Float64(M - Float64(0.5 * m))))
	t_1 = exp(Float64(n * Float64(m * -0.5)))
	tmp = 0.0
	if (l <= -720.0)
		tmp = exp(l);
	elseif (l <= -1.5e-48)
		tmp = t_1;
	elseif (l <= -3.3e-84)
		tmp = Float64(K * Float64(0.5 * Float64(m * sin(M))));
	elseif (l <= -1.45e-93)
		tmp = t_0;
	elseif (l <= -2e-169)
		tmp = t_1;
	elseif (l <= -9e-218)
		tmp = t_0;
	elseif (l <= 4.6e-304)
		tmp = Float64(-0.5 * Float64(sin(Float64(n * Float64(0.5 * K))) * Float64(m * K)));
	elseif (l <= 5.8e-15)
		tmp = t_0;
	else
		tmp = exp(Float64(-l));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp((n * (M - (0.5 * m))));
	t_1 = exp((n * (m * -0.5)));
	tmp = 0.0;
	if (l <= -720.0)
		tmp = exp(l);
	elseif (l <= -1.5e-48)
		tmp = t_1;
	elseif (l <= -3.3e-84)
		tmp = K * (0.5 * (m * sin(M)));
	elseif (l <= -1.45e-93)
		tmp = t_0;
	elseif (l <= -2e-169)
		tmp = t_1;
	elseif (l <= -9e-218)
		tmp = t_0;
	elseif (l <= 4.6e-304)
		tmp = -0.5 * (sin((n * (0.5 * K))) * (m * K));
	elseif (l <= 5.8e-15)
		tmp = t_0;
	else
		tmp = exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(n * N[(M - N[(0.5 * m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(n * N[(m * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -720.0], N[Exp[l], $MachinePrecision], If[LessEqual[l, -1.5e-48], t$95$1, If[LessEqual[l, -3.3e-84], N[(K * N[(0.5 * N[(m * N[Sin[M], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -1.45e-93], t$95$0, If[LessEqual[l, -2e-169], t$95$1, If[LessEqual[l, -9e-218], t$95$0, If[LessEqual[l, 4.6e-304], N[(-0.5 * N[(N[Sin[N[(n * N[(0.5 * K), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(m * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.8e-15], t$95$0, N[Exp[(-l)], $MachinePrecision]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{n \cdot \left(M - 0.5 \cdot m\right)}\\
t_1 := e^{n \cdot \left(m \cdot -0.5\right)}\\
\mathbf{if}\;\ell \leq -720:\\
\;\;\;\;e^{\ell}\\

\mathbf{elif}\;\ell \leq -1.5 \cdot 10^{-48}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -3.3 \cdot 10^{-84}:\\
\;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\

\mathbf{elif}\;\ell \leq -1.45 \cdot 10^{-93}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-169}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -9 \cdot 10^{-218}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 4.6 \cdot 10^{-304}:\\
\;\;\;\;-0.5 \cdot \left(\sin \left(n \cdot \left(0.5 \cdot K\right)\right) \cdot \left(m \cdot K\right)\right)\\

\mathbf{elif}\;\ell \leq 5.8 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


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

    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 n around 0 63.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. *-commutative10.0%

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

      \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
    12. Step-by-step derivation
      1. pow110.0%

        \[\leadsto \color{blue}{{\left(e^{-\ell} \cdot \cos M\right)}^{1}} \]
      2. add-sqr-sqrt10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}} \cdot \cos M\right)}^{1} \]
      3. sqrt-unprod10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}} \cdot \cos M\right)}^{1} \]
      4. sqr-neg10.0%

        \[\leadsto {\left(e^{\sqrt{\color{blue}{\ell \cdot \ell}}} \cdot \cos M\right)}^{1} \]
      5. sqrt-unprod0.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}} \cdot \cos M\right)}^{1} \]
      6. add-sqr-sqrt81.0%

        \[\leadsto {\left(e^{\color{blue}{\ell}} \cdot \cos M\right)}^{1} \]
    13. Applied egg-rr81.0%

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

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

        \[\leadsto e^{\ell} \cdot \color{blue}{\cos \left(-M\right)} \]
      3. *-commutative81.0%

        \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\ell}} \]
      4. cos-neg81.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\ell} \]
    15. Simplified81.0%

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

      \[\leadsto \color{blue}{e^{\ell}} \]

    if -720 < l < -1.5e-48 or -1.4499999999999999e-93 < l < -2.00000000000000004e-169

    1. Initial program 73.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg42.7%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*63.8%

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

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

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

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right) \cdot n}} \]
      2. metadata-eval69.2%

        \[\leadsto e^{\left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n} \]
      3. distribute-lft-neg-in69.2%

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right)} \cdot n} \]
      4. distribute-lft-neg-out69.2%

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

        \[\leadsto e^{-\color{blue}{n \cdot \left(0.5 \cdot m\right)}} \]
      6. distribute-rgt-neg-out69.2%

        \[\leadsto e^{\color{blue}{n \cdot \left(-0.5 \cdot m\right)}} \]
      7. distribute-lft-neg-in69.2%

        \[\leadsto e^{n \cdot \color{blue}{\left(\left(-0.5\right) \cdot m\right)}} \]
      8. metadata-eval69.2%

        \[\leadsto e^{n \cdot \left(\color{blue}{-0.5} \cdot m\right)} \]
    14. Simplified69.2%

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

    if -1.5e-48 < l < -3.29999999999999984e-84

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
    11. Taylor expanded in K around 0 9.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    12. Step-by-step derivation
      1. cos-neg9.1%

        \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    13. Simplified9.1%

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

      \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
    15. Step-by-step derivation
      1. associate-*r*9.2%

        \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(-M\right)\right)} \]
      2. sin-neg9.2%

        \[\leadsto \cos M + -0.5 \cdot \left(\left(K \cdot m\right) \cdot \color{blue}{\left(-\sin M\right)}\right) \]
    16. Simplified9.2%

      \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \left(-\sin M\right)\right)} \]
    17. Taylor expanded in K around inf 29.1%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)} \]
    18. Step-by-step derivation
      1. associate-*r*29.1%

        \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(m \cdot \sin M\right)} \]
      2. *-commutative29.1%

        \[\leadsto \color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m \cdot \sin M\right) \]
      3. associate-*l*29.1%

        \[\leadsto \color{blue}{K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)} \]
    19. Simplified29.1%

      \[\leadsto \color{blue}{K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)} \]

    if -3.29999999999999984e-84 < l < -1.4499999999999999e-93 or -2.00000000000000004e-169 < l < -8.99999999999999953e-218 or 4.5999999999999999e-304 < l < 5.80000000000000037e-15

    1. Initial program 82.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg71.8%

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

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

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

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

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

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

    if -8.99999999999999953e-218 < l < 4.5999999999999999e-304

    1. Initial program 67.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
    11. Taylor expanded in K around 0 2.4%

      \[\leadsto \color{blue}{\cos \left(-M\right)} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    12. Step-by-step derivation
      1. cos-neg2.4%

        \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    13. Simplified2.4%

      \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    14. Taylor expanded in K around inf 16.6%

      \[\leadsto \color{blue}{-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
    15. Step-by-step derivation
      1. associate-*r*16.6%

        \[\leadsto \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)} \]
      2. associate-*r*16.6%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(\color{blue}{\left(0.5 \cdot K\right) \cdot n} - M\right)\right) \]
      3. *-commutative16.6%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot n - M\right)\right) \]
      4. *-commutative16.6%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(\color{blue}{n \cdot \left(K \cdot 0.5\right)} - M\right)\right) \]
      5. *-commutative16.6%

        \[\leadsto \color{blue}{\left(K \cdot -0.5\right)} \cdot \left(m \cdot \sin \left(n \cdot \left(K \cdot 0.5\right) - M\right)\right) \]
    16. Simplified16.6%

      \[\leadsto \color{blue}{\left(K \cdot -0.5\right) \cdot \left(m \cdot \sin \left(n \cdot \left(K \cdot 0.5\right) - M\right)\right)} \]
    17. Taylor expanded in M around 0 30.8%

      \[\leadsto \color{blue}{-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right)\right)\right)\right)} \]
    18. Step-by-step derivation
      1. associate-*r*30.8%

        \[\leadsto -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(0.5 \cdot \left(K \cdot n\right)\right)\right)} \]
      2. associate-*r*30.8%

        \[\leadsto -0.5 \cdot \left(\left(K \cdot m\right) \cdot \sin \color{blue}{\left(\left(0.5 \cdot K\right) \cdot n\right)}\right) \]
      3. *-commutative30.8%

        \[\leadsto -0.5 \cdot \left(\left(K \cdot m\right) \cdot \sin \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot n\right)\right) \]
      4. *-commutative30.8%

        \[\leadsto -0.5 \cdot \left(\left(K \cdot m\right) \cdot \sin \color{blue}{\left(n \cdot \left(K \cdot 0.5\right)\right)}\right) \]
    19. Simplified30.8%

      \[\leadsto \color{blue}{-0.5 \cdot \left(\left(K \cdot m\right) \cdot \sin \left(n \cdot \left(K \cdot 0.5\right)\right)\right)} \]

    if 5.80000000000000037e-15 < l

    1. Initial program 81.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 n around 0 69.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg75.9%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*82.7%

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

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

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    13. Step-by-step derivation
      1. mul-1-neg92.1%

        \[\leadsto e^{\color{blue}{-\ell}} \]
    14. Simplified92.1%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  3. Recombined 6 regimes into one program.
  4. Final simplification66.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -720:\\ \;\;\;\;e^{\ell}\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{-48}:\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq -3.3 \cdot 10^{-84}:\\ \;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\ \mathbf{elif}\;\ell \leq -1.45 \cdot 10^{-93}:\\ \;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-169}:\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq -9 \cdot 10^{-218}:\\ \;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ \mathbf{elif}\;\ell \leq 4.6 \cdot 10^{-304}:\\ \;\;\;\;-0.5 \cdot \left(\sin \left(n \cdot \left(0.5 \cdot K\right)\right) \cdot \left(m \cdot K\right)\right)\\ \mathbf{elif}\;\ell \leq 5.8 \cdot 10^{-15}:\\ \;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 63.6% accurate, 3.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -720:\\
\;\;\;\;e^{\ell}\\

\mathbf{elif}\;\ell \leq -8 \cdot 10^{-51}:\\
\;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\

\mathbf{elif}\;\ell \leq -6.2 \cdot 10^{-84}:\\
\;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\

\mathbf{elif}\;\ell \leq 3.6 \cdot 10^{-18}:\\
\;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


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

    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 n around 0 63.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. *-commutative10.0%

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

      \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
    12. Step-by-step derivation
      1. pow110.0%

        \[\leadsto \color{blue}{{\left(e^{-\ell} \cdot \cos M\right)}^{1}} \]
      2. add-sqr-sqrt10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}} \cdot \cos M\right)}^{1} \]
      3. sqrt-unprod10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}} \cdot \cos M\right)}^{1} \]
      4. sqr-neg10.0%

        \[\leadsto {\left(e^{\sqrt{\color{blue}{\ell \cdot \ell}}} \cdot \cos M\right)}^{1} \]
      5. sqrt-unprod0.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}} \cdot \cos M\right)}^{1} \]
      6. add-sqr-sqrt81.0%

        \[\leadsto {\left(e^{\color{blue}{\ell}} \cdot \cos M\right)}^{1} \]
    13. Applied egg-rr81.0%

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

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

        \[\leadsto e^{\ell} \cdot \color{blue}{\cos \left(-M\right)} \]
      3. *-commutative81.0%

        \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\ell}} \]
      4. cos-neg81.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\ell} \]
    15. Simplified81.0%

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

      \[\leadsto \color{blue}{e^{\ell}} \]

    if -720 < l < -8.0000000000000001e-51

    1. Initial program 70.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg30.6%

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*60.6%

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

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

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

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right) \cdot n}} \]
      2. metadata-eval70.6%

        \[\leadsto e^{\left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n} \]
      3. distribute-lft-neg-in70.6%

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right)} \cdot n} \]
      4. distribute-lft-neg-out70.6%

        \[\leadsto e^{\color{blue}{-\left(0.5 \cdot m\right) \cdot n}} \]
      5. *-commutative70.6%

        \[\leadsto e^{-\color{blue}{n \cdot \left(0.5 \cdot m\right)}} \]
      6. distribute-rgt-neg-out70.6%

        \[\leadsto e^{\color{blue}{n \cdot \left(-0.5 \cdot m\right)}} \]
      7. distribute-lft-neg-in70.6%

        \[\leadsto e^{n \cdot \color{blue}{\left(\left(-0.5\right) \cdot m\right)}} \]
      8. metadata-eval70.6%

        \[\leadsto e^{n \cdot \left(\color{blue}{-0.5} \cdot m\right)} \]
    14. Simplified70.6%

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

    if -8.0000000000000001e-51 < l < -6.20000000000000003e-84

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
    11. Taylor expanded in K around 0 9.1%

      \[\leadsto \color{blue}{\cos \left(-M\right)} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    12. Step-by-step derivation
      1. cos-neg9.1%

        \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
    13. Simplified9.1%

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

      \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
    15. Step-by-step derivation
      1. associate-*r*9.2%

        \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(-M\right)\right)} \]
      2. sin-neg9.2%

        \[\leadsto \cos M + -0.5 \cdot \left(\left(K \cdot m\right) \cdot \color{blue}{\left(-\sin M\right)}\right) \]
    16. Simplified9.2%

      \[\leadsto \cos M + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \left(-\sin M\right)\right)} \]
    17. Taylor expanded in K around inf 29.1%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \sin M\right)\right)} \]
    18. Step-by-step derivation
      1. associate-*r*29.1%

        \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(m \cdot \sin M\right)} \]
      2. *-commutative29.1%

        \[\leadsto \color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m \cdot \sin M\right) \]
      3. associate-*l*29.1%

        \[\leadsto \color{blue}{K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)} \]
    19. Simplified29.1%

      \[\leadsto \color{blue}{K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)} \]

    if -6.20000000000000003e-84 < l < 3.6000000000000001e-18

    1. Initial program 79.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 n around 0 58.1%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg65.1%

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

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

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

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

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

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

    if 3.6000000000000001e-18 < l

    1. Initial program 81.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 n around 0 69.4%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg76.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    13. Step-by-step derivation
      1. mul-1-neg91.0%

        \[\leadsto e^{\color{blue}{-\ell}} \]
    14. Simplified91.0%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification65.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -720:\\ \;\;\;\;e^{\ell}\\ \mathbf{elif}\;\ell \leq -8 \cdot 10^{-51}:\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq -6.2 \cdot 10^{-84}:\\ \;\;\;\;K \cdot \left(0.5 \cdot \left(m \cdot \sin M\right)\right)\\ \mathbf{elif}\;\ell \leq 3.6 \cdot 10^{-18}:\\ \;\;\;\;e^{n \cdot \left(M - 0.5 \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 60.6% accurate, 3.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -720:\\
\;\;\;\;e^{\ell}\\

\mathbf{elif}\;\ell \leq 3.5 \cdot 10^{-13}:\\
\;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


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

    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 n around 0 63.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. *-commutative10.0%

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

      \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
    12. Step-by-step derivation
      1. pow110.0%

        \[\leadsto \color{blue}{{\left(e^{-\ell} \cdot \cos M\right)}^{1}} \]
      2. add-sqr-sqrt10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}} \cdot \cos M\right)}^{1} \]
      3. sqrt-unprod10.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}} \cdot \cos M\right)}^{1} \]
      4. sqr-neg10.0%

        \[\leadsto {\left(e^{\sqrt{\color{blue}{\ell \cdot \ell}}} \cdot \cos M\right)}^{1} \]
      5. sqrt-unprod0.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}} \cdot \cos M\right)}^{1} \]
      6. add-sqr-sqrt81.0%

        \[\leadsto {\left(e^{\color{blue}{\ell}} \cdot \cos M\right)}^{1} \]
    13. Applied egg-rr81.0%

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

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

        \[\leadsto e^{\ell} \cdot \color{blue}{\cos \left(-M\right)} \]
      3. *-commutative81.0%

        \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\ell}} \]
      4. cos-neg81.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\ell} \]
    15. Simplified81.0%

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

      \[\leadsto \color{blue}{e^{\ell}} \]

    if -720 < l < 3.5000000000000002e-13

    1. Initial program 79.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg65.5%

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

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

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

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    9. Taylor expanded in M around 0 54.9%

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)\right)}} \]
    10. Step-by-step derivation
      1. associate--r+54.9%

        \[\leadsto e^{\color{blue}{\left(\left|m - n\right| - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)}} \]
      2. fabs-sub54.9%

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*54.9%

        \[\leadsto e^{\left(\left|n - m\right| - \ell\right) - \color{blue}{\left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}} \]
    11. Simplified54.9%

      \[\leadsto \color{blue}{e^{\left(\left|n - m\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}} \]
    12. Taylor expanded in n around inf 36.5%

      \[\leadsto e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    13. Step-by-step derivation
      1. associate-*r*36.5%

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right) \cdot n}} \]
      2. metadata-eval36.5%

        \[\leadsto e^{\left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n} \]
      3. distribute-lft-neg-in36.5%

        \[\leadsto e^{\color{blue}{\left(-0.5 \cdot m\right)} \cdot n} \]
      4. distribute-lft-neg-out36.5%

        \[\leadsto e^{\color{blue}{-\left(0.5 \cdot m\right) \cdot n}} \]
      5. *-commutative36.5%

        \[\leadsto e^{-\color{blue}{n \cdot \left(0.5 \cdot m\right)}} \]
      6. distribute-rgt-neg-out36.5%

        \[\leadsto e^{\color{blue}{n \cdot \left(-0.5 \cdot m\right)}} \]
      7. distribute-lft-neg-in36.5%

        \[\leadsto e^{n \cdot \color{blue}{\left(\left(-0.5\right) \cdot m\right)}} \]
      8. metadata-eval36.5%

        \[\leadsto e^{n \cdot \left(\color{blue}{-0.5} \cdot m\right)} \]
    14. Simplified36.5%

      \[\leadsto e^{\color{blue}{n \cdot \left(-0.5 \cdot m\right)}} \]

    if 3.5000000000000002e-13 < l

    1. Initial program 80.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 n around 0 68.6%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(n \cdot \left(0.5 \cdot m - M\right) + {\left(0.5 \cdot m - M\right)}^{2}\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. +-commutative68.6%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. unpow268.6%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      3. distribute-rgt-out72.7%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
      4. *-commutative72.7%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{m \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      5. *-commutative72.7%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(\color{blue}{m \cdot 0.5} - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. Simplified72.7%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    6. Taylor expanded in K around 0 75.6%

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg75.6%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate-*r*75.6%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      3. sin-neg75.6%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    8. Simplified75.6%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    9. Taylor expanded in M around 0 82.5%

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)\right)}} \]
    10. Step-by-step derivation
      1. associate--r+82.5%

        \[\leadsto e^{\color{blue}{\left(\left|m - n\right| - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)}} \]
      2. fabs-sub82.5%

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*82.5%

        \[\leadsto e^{\left(\left|n - m\right| - \ell\right) - \color{blue}{\left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}} \]
    11. Simplified82.5%

      \[\leadsto \color{blue}{e^{\left(\left|n - m\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}} \]
    12. Taylor expanded in l around inf 93.4%

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    13. Step-by-step derivation
      1. mul-1-neg93.4%

        \[\leadsto e^{\color{blue}{-\ell}} \]
    14. Simplified93.4%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification62.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -720:\\ \;\;\;\;e^{\ell}\\ \mathbf{elif}\;\ell \leq 3.5 \cdot 10^{-13}:\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 49.4% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1720:\\ \;\;\;\;e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= l -1720.0) (exp l) (exp (- l))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (l <= -1720.0) {
		tmp = exp(l);
	} else {
		tmp = exp(-l);
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: tmp
    if (l <= (-1720.0d0)) then
        tmp = exp(l)
    else
        tmp = exp(-l)
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (l <= -1720.0) {
		tmp = Math.exp(l);
	} else {
		tmp = Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if l <= -1720.0:
		tmp = math.exp(l)
	else:
		tmp = math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (l <= -1720.0)
		tmp = exp(l);
	else
		tmp = exp(Float64(-l));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (l <= -1720.0)
		tmp = exp(l);
	else
		tmp = exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[l, -1720.0], N[Exp[l], $MachinePrecision], N[Exp[(-l)], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1720:\\
\;\;\;\;e^{\ell}\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1720

    1. Initial program 76.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 n around 0 64.3%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(n \cdot \left(0.5 \cdot m - M\right) + {\left(0.5 \cdot m - M\right)}^{2}\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. +-commutative64.3%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. unpow264.3%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      3. distribute-rgt-out73.3%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
      4. *-commutative73.3%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{m \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      5. *-commutative73.3%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(\color{blue}{m \cdot 0.5} - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. Simplified73.3%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    6. Taylor expanded in l around inf 15.3%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    7. Step-by-step derivation
      1. mul-1-neg15.3%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    8. Simplified15.3%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    9. Taylor expanded in K around 0 10.2%

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
    10. Step-by-step derivation
      1. cos-neg10.2%

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. *-commutative10.2%

        \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
    11. Simplified10.2%

      \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
    12. Step-by-step derivation
      1. pow110.2%

        \[\leadsto \color{blue}{{\left(e^{-\ell} \cdot \cos M\right)}^{1}} \]
      2. add-sqr-sqrt10.2%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}} \cdot \cos M\right)}^{1} \]
      3. sqrt-unprod10.2%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}} \cdot \cos M\right)}^{1} \]
      4. sqr-neg10.2%

        \[\leadsto {\left(e^{\sqrt{\color{blue}{\ell \cdot \ell}}} \cdot \cos M\right)}^{1} \]
      5. sqrt-unprod0.0%

        \[\leadsto {\left(e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}} \cdot \cos M\right)}^{1} \]
      6. add-sqr-sqrt80.7%

        \[\leadsto {\left(e^{\color{blue}{\ell}} \cdot \cos M\right)}^{1} \]
    13. Applied egg-rr80.7%

      \[\leadsto \color{blue}{{\left(e^{\ell} \cdot \cos M\right)}^{1}} \]
    14. Step-by-step derivation
      1. unpow180.7%

        \[\leadsto \color{blue}{e^{\ell} \cdot \cos M} \]
      2. cos-neg80.7%

        \[\leadsto e^{\ell} \cdot \color{blue}{\cos \left(-M\right)} \]
      3. *-commutative80.7%

        \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\ell}} \]
      4. cos-neg80.7%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\ell} \]
    15. Simplified80.7%

      \[\leadsto \color{blue}{\cos M \cdot e^{\ell}} \]
    16. Taylor expanded in M around 0 80.7%

      \[\leadsto \color{blue}{e^{\ell}} \]

    if -1720 < l

    1. Initial program 79.7%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in n around 0 62.4%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(n \cdot \left(0.5 \cdot m - M\right) + {\left(0.5 \cdot m - M\right)}^{2}\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. +-commutative62.4%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. unpow262.4%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      3. distribute-rgt-out65.9%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
      4. *-commutative65.9%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{m \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      5. *-commutative65.9%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(\color{blue}{m \cdot 0.5} - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. Simplified65.9%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    6. Taylor expanded in K around 0 68.8%

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot e^{\left(-\left(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)} \]
    7. Step-by-step derivation
      1. cos-neg68.8%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate-*r*68.8%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      3. sin-neg68.8%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    8. Simplified68.8%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    9. Taylor expanded in M around 0 65.2%

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)\right)}} \]
    10. Step-by-step derivation
      1. associate--r+65.2%

        \[\leadsto e^{\color{blue}{\left(\left|m - n\right| - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)}} \]
      2. fabs-sub65.2%

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*65.2%

        \[\leadsto e^{\left(\left|n - m\right| - \ell\right) - \color{blue}{\left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}} \]
    11. Simplified65.2%

      \[\leadsto \color{blue}{e^{\left(\left|n - m\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}} \]
    12. Taylor expanded in l around inf 40.4%

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    13. Step-by-step derivation
      1. mul-1-neg40.4%

        \[\leadsto e^{\color{blue}{-\ell}} \]
    14. Simplified40.4%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 18: 24.1% accurate, 4.2× speedup?

\[\begin{array}{l} \\ e^{\ell} \end{array} \]
(FPCore (K m n M l) :precision binary64 (exp l))
double code(double K, double m, double n, double M, double l) {
	return exp(l);
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = exp(l)
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.exp(l);
}
def code(K, m, n, M, l):
	return math.exp(l)
function code(K, m, n, M, l)
	return exp(l)
end
function tmp = code(K, m, n, M, l)
	tmp = exp(l);
end
code[K_, m_, n_, M_, l_] := N[Exp[l], $MachinePrecision]
\begin{array}{l}

\\
e^{\ell}
\end{array}
Derivation
  1. Initial program 79.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 n around 0 62.8%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(n \cdot \left(0.5 \cdot m - M\right) + {\left(0.5 \cdot m - M\right)}^{2}\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
  4. Step-by-step derivation
    1. +-commutative62.8%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. unpow262.8%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    3. distribute-rgt-out67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. *-commutative67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{m \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. *-commutative67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(\color{blue}{m \cdot 0.5} - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
  5. Simplified67.5%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
  6. Taylor expanded in l around inf 29.7%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  7. Step-by-step derivation
    1. mul-1-neg29.7%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
  8. Simplified29.7%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
  9. Taylor expanded in K around 0 33.8%

    \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
  10. Step-by-step derivation
    1. cos-neg33.8%

      \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
    2. *-commutative33.8%

      \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
  11. Simplified33.8%

    \[\leadsto \color{blue}{e^{-\ell} \cdot \cos M} \]
  12. Step-by-step derivation
    1. pow133.8%

      \[\leadsto \color{blue}{{\left(e^{-\ell} \cdot \cos M\right)}^{1}} \]
    2. add-sqr-sqrt4.9%

      \[\leadsto {\left(e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}} \cdot \cos M\right)}^{1} \]
    3. sqrt-unprod7.6%

      \[\leadsto {\left(e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}} \cdot \cos M\right)}^{1} \]
    4. sqr-neg7.6%

      \[\leadsto {\left(e^{\sqrt{\color{blue}{\ell \cdot \ell}}} \cdot \cos M\right)}^{1} \]
    5. sqrt-unprod2.7%

      \[\leadsto {\left(e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}} \cdot \cos M\right)}^{1} \]
    6. add-sqr-sqrt23.4%

      \[\leadsto {\left(e^{\color{blue}{\ell}} \cdot \cos M\right)}^{1} \]
  13. Applied egg-rr23.4%

    \[\leadsto \color{blue}{{\left(e^{\ell} \cdot \cos M\right)}^{1}} \]
  14. Step-by-step derivation
    1. unpow123.4%

      \[\leadsto \color{blue}{e^{\ell} \cdot \cos M} \]
    2. cos-neg23.4%

      \[\leadsto e^{\ell} \cdot \color{blue}{\cos \left(-M\right)} \]
    3. *-commutative23.4%

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\ell}} \]
    4. cos-neg23.4%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\ell} \]
  15. Simplified23.4%

    \[\leadsto \color{blue}{\cos M \cdot e^{\ell}} \]
  16. Taylor expanded in M around 0 23.4%

    \[\leadsto \color{blue}{e^{\ell}} \]
  17. Add Preprocessing

Alternative 19: 7.0% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \cos M \end{array} \]
(FPCore (K m n M l) :precision binary64 (cos M))
double code(double K, double m, double n, double M, double l) {
	return cos(M);
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = cos(m_1)
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M);
}
def code(K, m, n, M, l):
	return math.cos(M)
function code(K, m, n, M, l)
	return cos(M)
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M);
end
code[K_, m_, n_, M_, l_] := N[Cos[M], $MachinePrecision]
\begin{array}{l}

\\
\cos M
\end{array}
Derivation
  1. Initial program 79.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 n around 0 62.8%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(n \cdot \left(0.5 \cdot m - M\right) + {\left(0.5 \cdot m - M\right)}^{2}\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
  4. Step-by-step derivation
    1. +-commutative62.8%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. unpow262.8%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    3. distribute-rgt-out67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. *-commutative67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{m \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. *-commutative67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(\color{blue}{m \cdot 0.5} - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
  5. Simplified67.5%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
  6. Taylor expanded in l around inf 29.7%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  7. Step-by-step derivation
    1. mul-1-neg29.7%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
  8. Simplified29.7%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
  9. Taylor expanded in l around 0 6.1%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
  10. Taylor expanded in K around 0 6.5%

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  11. Step-by-step derivation
    1. cos-neg6.5%

      \[\leadsto \color{blue}{\cos M} \]
  12. Simplified6.5%

    \[\leadsto \color{blue}{\cos M} \]
  13. Add Preprocessing

Alternative 20: 7.0% accurate, 425.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (K m n M l) :precision binary64 1.0)
double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = 1.0d0
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
def code(K, m, n, M, l):
	return 1.0
function code(K, m, n, M, l)
	return 1.0
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0;
end
code[K_, m_, n_, M_, l_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 79.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 n around 0 62.8%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(n \cdot \left(0.5 \cdot m - M\right) + {\left(0.5 \cdot m - M\right)}^{2}\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
  4. Step-by-step derivation
    1. +-commutative62.8%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left({\left(0.5 \cdot m - M\right)}^{2} + n \cdot \left(0.5 \cdot m - M\right)\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. unpow262.8%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(0.5 \cdot m - M\right)} + n \cdot \left(0.5 \cdot m - M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    3. distribute-rgt-out67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(0.5 \cdot m - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. *-commutative67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(\color{blue}{m \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot m - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. *-commutative67.5%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\left(m \cdot 0.5 - M\right) \cdot \left(\left(\color{blue}{m \cdot 0.5} - M\right) + n\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
  5. Simplified67.5%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(m \cdot 0.5 - M\right) \cdot \left(\left(m \cdot 0.5 - M\right) + n\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
  6. Taylor expanded in l around inf 29.7%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  7. Step-by-step derivation
    1. mul-1-neg29.7%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
  8. Simplified29.7%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
  9. Taylor expanded in l around 0 6.1%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
  10. Taylor expanded in M around inf 5.6%

    \[\leadsto \cos \color{blue}{\left(M \cdot \left(0.5 \cdot \frac{K \cdot \left(m + n\right)}{M} - 1\right)\right)} \]
  11. Taylor expanded in M around 0 6.1%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)} \]
  12. Step-by-step derivation
    1. associate-*r*6.1%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot \left(m + n\right)\right)} \]
    2. *-commutative6.1%

      \[\leadsto \cos \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m + n\right)\right) \]
    3. +-commutative6.1%

      \[\leadsto \cos \left(\left(K \cdot 0.5\right) \cdot \color{blue}{\left(n + m\right)}\right) \]
  13. Simplified6.1%

    \[\leadsto \color{blue}{\cos \left(\left(K \cdot 0.5\right) \cdot \left(n + m\right)\right)} \]
  14. Taylor expanded in n around inf 5.6%

    \[\leadsto \cos \color{blue}{\left(n \cdot \left(0.5 \cdot K + 0.5 \cdot \frac{K \cdot m}{n}\right)\right)} \]
  15. Step-by-step derivation
    1. distribute-lft-out5.6%

      \[\leadsto \cos \left(n \cdot \color{blue}{\left(0.5 \cdot \left(K + \frac{K \cdot m}{n}\right)\right)}\right) \]
    2. associate-/l*5.5%

      \[\leadsto \cos \left(n \cdot \left(0.5 \cdot \left(K + \color{blue}{K \cdot \frac{m}{n}}\right)\right)\right) \]
  16. Simplified5.5%

    \[\leadsto \cos \color{blue}{\left(n \cdot \left(0.5 \cdot \left(K + K \cdot \frac{m}{n}\right)\right)\right)} \]
  17. Taylor expanded in K around 0 6.5%

    \[\leadsto \color{blue}{1} \]
  18. Add Preprocessing

Reproduce

?
herbie shell --seed 2024107 
(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)))))))