Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.7% → 96.6%
Time: 17.9s
Alternatives: 14
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 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: 75.7% 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.6% accurate, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 2: 87.1% accurate, 1.3× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

    if 55 < n

    1. Initial program 69.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(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-neg100.0%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    8. Simplified100.0%

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

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

Alternative 3: 73.8% accurate, 1.3× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 55 < n

    1. Initial program 69.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(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-neg100.0%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    8. Simplified100.0%

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

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

Alternative 4: 80.4% accurate, 1.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -0.0013500000000000001 or 2.6e-42 < M

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

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

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

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

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

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

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

    if -0.0013500000000000001 < M < 2.6e-42

    1. Initial program 70.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.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 49.8% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;m \leq -1.7 \cdot 10^{-175}:\\
\;\;\;\;\cos M \cdot {\left(e^{M}\right)}^{n}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if m < -1.45000000000000013e-57

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.45000000000000013e-57 < m < -1.7e-175

    1. Initial program 83.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{M \cdot n} \]
      2. exp-prod51.9%

        \[\leadsto \cos M \cdot \color{blue}{{\left(e^{M}\right)}^{n}} \]
    10. Simplified51.9%

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

    if -1.7e-175 < m < 2.05e-142

    1. Initial program 82.0%

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

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

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

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

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

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

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

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

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

    if 2.05e-142 < m

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1.45 \cdot 10^{-57}:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)\right)}\\ \mathbf{elif}\;m \leq -1.7 \cdot 10^{-175}:\\ \;\;\;\;\cos M \cdot {\left(e^{M}\right)}^{n}\\ \mathbf{elif}\;m \leq 2.05 \cdot 10^{-142}:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(m \cdot \left(0.5 \cdot K\right) - M\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 73.7% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 56 < n

    1. Initial program 69.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(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-neg100.0%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    8. Simplified100.0%

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

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

Alternative 7: 57.3% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(-M\right) \cdot e^{M \cdot n}\\
\mathbf{if}\;\ell \leq -5.7 \cdot 10^{+16}:\\
\;\;\;\;\cos \left(\left(m \cdot 0.5\right) \cdot K\right) \cdot e^{\ell}\\

\mathbf{elif}\;\ell \leq -1 \cdot 10^{-238}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 1.35 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -5.7e16

    1. Initial program 67.3%

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\cos \color{blue}{\left(K \cdot \left(0.5 \cdot m\right)\right)} \cdot e^{-\ell}\right)}^{1} \]
      3. add-sqr-sqrt19.3%

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

        \[\leadsto {\left(\cos \left(K \cdot \left(0.5 \cdot m\right)\right) \cdot e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}}\right)}^{1} \]
      5. sqr-neg19.3%

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

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

        \[\leadsto {\left(\cos \left(K \cdot \left(0.5 \cdot m\right)\right) \cdot e^{\color{blue}{\ell}}\right)}^{1} \]
    10. Applied egg-rr61.6%

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

        \[\leadsto \color{blue}{\cos \left(K \cdot \left(0.5 \cdot m\right)\right) \cdot e^{\ell}} \]
    12. Simplified61.6%

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

    if -5.7e16 < l < -9.9999999999999999e-239 or 4.40000000000000012e-144 < l < 1.35000000000000002e-11

    1. Initial program 77.9%

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999999e-239 < l < 4.40000000000000012e-144

    1. Initial program 81.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.35000000000000002e-11 < l

    1. Initial program 75.3%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.7 \cdot 10^{+16}:\\ \;\;\;\;\cos \left(\left(m \cdot 0.5\right) \cdot K\right) \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-238}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{M \cdot n}\\ \mathbf{elif}\;\ell \leq 4.4 \cdot 10^{-144}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq 1.35 \cdot 10^{-11}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{M \cdot n}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 50.0% accurate, 1.9× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if m < -2.94999999999999983e-40

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.94999999999999983e-40 < m < -2.2e-175

    1. Initial program 80.8%

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

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

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

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

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

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

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

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

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

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

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

    if -2.2e-175 < m < 5.7999999999999999e-141

    1. Initial program 82.0%

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

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

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

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

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

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

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

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

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

    if 5.7999999999999999e-141 < m

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -2.95 \cdot 10^{-40}:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + 0.5 \cdot \left(m \cdot \left(n + m \cdot 0.5\right)\right)\right)}\\ \mathbf{elif}\;m \leq -2.2 \cdot 10^{-175}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{M \cdot n}\\ \mathbf{elif}\;m \leq 5.8 \cdot 10^{-141}:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(m \cdot \left(0.5 \cdot K\right) - M\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 48.9% accurate, 1.9× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 1.35 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.60000000000000008e-238 or 3.09999999999999998e-150 < l < 1.35000000000000002e-11

    1. Initial program 74.1%

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

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

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

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

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

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

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

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

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

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

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

    if -5.60000000000000008e-238 < l < 3.09999999999999998e-150

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.35000000000000002e-11 < l

    1. Initial program 75.3%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.6 \cdot 10^{-238}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{M \cdot n}\\ \mathbf{elif}\;\ell \leq 3.1 \cdot 10^{-150}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(m \cdot -0.5\right)}\\ \mathbf{elif}\;\ell \leq 1.35 \cdot 10^{-11}:\\ \;\;\;\;\cos \left(-M\right) \cdot e^{M \cdot n}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 60.6% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.56 \cdot 10^{+34}:\\
\;\;\;\;\cos \left(\left(m \cdot 0.5\right) \cdot K\right) \cdot e^{\ell}\\

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

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


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

    1. Initial program 69.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\cos \color{blue}{\left(K \cdot \left(0.5 \cdot m\right)\right)} \cdot e^{-\ell}\right)}^{1} \]
      3. add-sqr-sqrt21.9%

        \[\leadsto {\left(\cos \left(K \cdot \left(0.5 \cdot m\right)\right) \cdot e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}}\right)}^{1} \]
      4. sqrt-unprod21.9%

        \[\leadsto {\left(\cos \left(K \cdot \left(0.5 \cdot m\right)\right) \cdot e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}}\right)}^{1} \]
      5. sqr-neg21.9%

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

        \[\leadsto {\left(\cos \left(K \cdot \left(0.5 \cdot m\right)\right) \cdot e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}\right)}^{1} \]
      7. add-sqr-sqrt60.9%

        \[\leadsto {\left(\cos \left(K \cdot \left(0.5 \cdot m\right)\right) \cdot e^{\color{blue}{\ell}}\right)}^{1} \]
    10. Applied egg-rr60.9%

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

        \[\leadsto \color{blue}{\cos \left(K \cdot \left(0.5 \cdot m\right)\right) \cdot e^{\ell}} \]
    12. Simplified60.9%

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

    if -1.5600000000000001e34 < l < 6.9000000000000001e-15

    1. Initial program 77.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.9000000000000001e-15 < l

    1. Initial program 75.6%

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

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

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

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

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

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

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

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

Alternative 11: 48.9% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1.35 \cdot 10^{-11}:\\
\;\;\;\;\cos \left(-M\right) \cdot e^{M \cdot n}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.35000000000000002e-11

    1. Initial program 75.8%

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

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

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

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

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

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

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

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

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

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

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

    if 1.35000000000000002e-11 < l

    1. Initial program 75.3%

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

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

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

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

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

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

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

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

Alternative 12: 36.0% accurate, 2.1× speedup?

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

\\
\cos M \cdot e^{-\ell}
\end{array}
Derivation
  1. Initial program 75.6%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos M \cdot e^{-\ell}} \]
  9. Final simplification40.3%

    \[\leadsto \cos M \cdot e^{-\ell} \]
  10. Add Preprocessing

Alternative 13: 35.7% 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.6%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{e^{-\ell}} \]
  10. Final simplification39.9%

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

Alternative 14: 7.0% accurate, 4.2× speedup?

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)} \]
  7. Step-by-step derivation
    1. *-commutative6.3%

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

      \[\leadsto \cos \left(\color{blue}{K \cdot \left(n \cdot 0.5\right)} - M\right) \]
  8. Simplified6.3%

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  10. Step-by-step derivation
    1. cos-neg6.7%

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified6.7%

    \[\leadsto \color{blue}{\cos M} \]
  12. Final simplification6.7%

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

Reproduce

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