Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.1% → 96.9%
Time: 29.9s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 76.1% accurate, 1.0× speedup?

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

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

Alternative 1: 96.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 87.3% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 77.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.89999999999999981e42 < n

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out86.5%

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    12. Simplified100.0%

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

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

Alternative 3: 72.5% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 72.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out79.4%

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

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

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

    if -7.49999999999999976e-126 < n < 1.46e10

    1. Initial program 82.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out70.8%

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

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

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

    if 1.46e10 < n

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out83.6%

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    12. Simplified98.4%

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

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

Alternative 4: 72.3% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 72.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out79.4%

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

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

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

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

    if -2.2000000000000001e-127 < n < 1.46e10

    1. Initial program 82.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out70.8%

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

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

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

    if 1.46e10 < n

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out83.6%

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    12. Simplified98.4%

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

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

Alternative 5: 81.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -2.12 \cdot 10^{-13} \lor \neg \left(M \leq 5.3 \cdot 10^{+14}\right):\\
\;\;\;\;e^{-{M}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -2.1200000000000001e-13 or 5.3e14 < M

    1. Initial program 75.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out87.8%

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{-{M}^{2}}} \]
    12. Simplified95.9%

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

    if -2.1200000000000001e-13 < M < 5.3e14

    1. Initial program 76.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out63.2%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 64.8% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;n \leq 55:\\
\;\;\;\;e^{-{M}^{2}}\\

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


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

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out85.9%

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

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

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

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

    if -7.6000000000000001e71 < n < 55

    1. Initial program 81.5%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out70.1%

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{-{M}^{2}}} \]
    12. Simplified63.0%

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

    if 55 < n

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out84.4%

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    12. Simplified98.4%

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

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

Alternative 7: 64.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3400000000000:\\
\;\;\;\;\cos M \cdot e^{\ell}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.4e12

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out71.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.4e12 < l < 0.0064999999999999997

    1. Initial program 67.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out75.6%

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

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

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

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

    if 0.0064999999999999997 < l

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out87.9%

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

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

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

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

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

        \[\leadsto \cos M \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. un-div-inv98.3%

        \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    13. Applied egg-rr98.3%

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

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

Alternative 8: 73.7% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -950000:\\
\;\;\;\;\cos M \cdot e^{\ell}\\

\mathbf{elif}\;\ell \leq 720:\\
\;\;\;\;e^{-{M}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -9.5e5

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.5e5 < l < 720

    1. Initial program 67.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out75.6%

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{-{M}^{2}}} \]
    12. Simplified68.2%

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

    if 720 < l

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out87.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -950000:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq 720:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 64.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3400000000000:\\
\;\;\;\;\cos M \cdot e^{\ell}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.4e12

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out71.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.4e12 < l < 0.0064999999999999997

    1. Initial program 67.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out75.6%

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

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

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

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

    if 0.0064999999999999997 < l

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out87.9%

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

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

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

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

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

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

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

Alternative 10: 54.8% accurate, 3.8× speedup?

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

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

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


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

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out74.0%

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

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

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

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

    if 0.0064999999999999997 < l

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
      3. distribute-rgt-out87.9%

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

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

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

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

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

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

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

Alternative 11: 35.3% 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(Float64(-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 75.7%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
    3. distribute-rgt-out77.1%

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

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

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

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

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

    \[\leadsto \color{blue}{e^{-\ell}} \]
  13. Final simplification31.8%

    \[\leadsto e^{-\ell} \]
  14. Add Preprocessing

Alternative 12: 6.9% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 75.7%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \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)} \]
    3. distribute-rgt-out77.1%

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  12. Taylor expanded in l around 0 6.4%

    \[\leadsto \color{blue}{\cos M} \]
  13. Final simplification6.4%

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

Reproduce

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