Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.2% → 96.4%
Time: 26.3s
Alternatives: 12
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 76.2% 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.4% 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 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 96.7%

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

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

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

    \[\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: 75.0% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;n \leq 950000:\\
\;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot e^{\left(t\_0 - M\right) \cdot \left(M - t\_0\right) + \left(\left|m - n\right| - \ell\right)}\\

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


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

    1. Initial program 70.4%

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

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

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

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

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

    if -9.1999999999999998e-129 < n < 9.5e5

    1. Initial program 89.3%

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

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

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

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

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

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

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

    if 9.5e5 < n

    1. Initial program 66.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 98.4%

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

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

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

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

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

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

Alternative 3: 75.0% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -9.2 \cdot 10^{-129}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\

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

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


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

    1. Initial program 70.4%

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

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

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

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

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

    if -9.1999999999999998e-129 < n < 9.2e5

    1. Initial program 89.3%

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(n \cdot \left(0.5 \cdot m - M\right) + {\left(0.5 \cdot m - M\right)}^{2}\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. +-commutative89.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. unpow289.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-out89.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. *-commutative89.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. *-commutative89.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. Simplified89.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)} \]

    if 9.2e5 < n

    1. Initial program 66.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 98.4%

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

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

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

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

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

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

Alternative 4: 63.3% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot \frac{m}{2} - M\right) \cdot e^{\left(m - n\right) + \left({n}^{2} \cdot 0.25 - \ell\right)}\\
\mathbf{if}\;n \leq -1.02 \cdot 10^{-200}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\

\mathbf{elif}\;n \leq 4.4 \cdot 10^{-172}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;n \leq 1.15 \cdot 10^{-7}:\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

\mathbf{elif}\;n \leq 750000:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if n < -1.02e-200

    1. Initial program 73.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 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 m around inf 52.8%

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

    if -1.02e-200 < n < 4.40000000000000018e-172 or 1.14999999999999997e-7 < n < 7.5e5

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

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

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

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

    if 4.40000000000000018e-172 < n < 1.14999999999999997e-7

    1. Initial program 88.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 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 M around inf 62.7%

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

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

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

    if 7.5e5 < n

    1. Initial program 66.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 98.4%

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

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

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

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

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

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

Alternative 5: 69.1% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -2.35 \cdot 10^{-201}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\

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

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


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

    1. Initial program 73.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 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 m around inf 52.8%

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

    if -2.34999999999999997e-201 < n < 7.5e5

    1. Initial program 88.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.5e5 < n

    1. Initial program 66.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 98.4%

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

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

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

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

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

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

Alternative 6: 64.2% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{-{M}^{2}}\\ \mathbf{if}\;n \leq -1.5 \cdot 10^{-247}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;n \leq 7.8 \cdot 10^{-237}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;n \leq 3.7 \cdot 10^{-172}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;n \leq 750000:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot {n}^{2}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos M) (exp (- (pow M 2.0))))))
   (if (<= n -1.5e-247)
     (* (cos M) (exp (* -0.25 (pow m 2.0))))
     (if (<= n 7.8e-237)
       t_0
       (if (<= n 3.7e-172)
         (* (cos M) (exp (- l)))
         (if (<= n 750000.0) t_0 (exp (* -0.25 (pow n 2.0)))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp(-pow(M, 2.0));
	double tmp;
	if (n <= -1.5e-247) {
		tmp = cos(M) * exp((-0.25 * pow(m, 2.0)));
	} else if (n <= 7.8e-237) {
		tmp = t_0;
	} else if (n <= 3.7e-172) {
		tmp = cos(M) * exp(-l);
	} else if (n <= 750000.0) {
		tmp = t_0;
	} else {
		tmp = exp((-0.25 * pow(n, 2.0)));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos(m_1) * exp(-(m_1 ** 2.0d0))
    if (n <= (-1.5d-247)) then
        tmp = cos(m_1) * exp(((-0.25d0) * (m ** 2.0d0)))
    else if (n <= 7.8d-237) then
        tmp = t_0
    else if (n <= 3.7d-172) then
        tmp = cos(m_1) * exp(-l)
    else if (n <= 750000.0d0) then
        tmp = t_0
    else
        tmp = exp(((-0.25d0) * (n ** 2.0d0)))
    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(-Math.pow(M, 2.0));
	double tmp;
	if (n <= -1.5e-247) {
		tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(m, 2.0)));
	} else if (n <= 7.8e-237) {
		tmp = t_0;
	} else if (n <= 3.7e-172) {
		tmp = Math.cos(M) * Math.exp(-l);
	} else if (n <= 750000.0) {
		tmp = t_0;
	} else {
		tmp = Math.exp((-0.25 * Math.pow(n, 2.0)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(M) * math.exp(-math.pow(M, 2.0))
	tmp = 0
	if n <= -1.5e-247:
		tmp = math.cos(M) * math.exp((-0.25 * math.pow(m, 2.0)))
	elif n <= 7.8e-237:
		tmp = t_0
	elif n <= 3.7e-172:
		tmp = math.cos(M) * math.exp(-l)
	elif n <= 750000.0:
		tmp = t_0
	else:
		tmp = math.exp((-0.25 * math.pow(n, 2.0)))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) * exp(Float64(-(M ^ 2.0))))
	tmp = 0.0
	if (n <= -1.5e-247)
		tmp = Float64(cos(M) * exp(Float64(-0.25 * (m ^ 2.0))));
	elseif (n <= 7.8e-237)
		tmp = t_0;
	elseif (n <= 3.7e-172)
		tmp = Float64(cos(M) * exp(Float64(-l)));
	elseif (n <= 750000.0)
		tmp = t_0;
	else
		tmp = exp(Float64(-0.25 * (n ^ 2.0)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = cos(M) * exp(-(M ^ 2.0));
	tmp = 0.0;
	if (n <= -1.5e-247)
		tmp = cos(M) * exp((-0.25 * (m ^ 2.0)));
	elseif (n <= 7.8e-237)
		tmp = t_0;
	elseif (n <= 3.7e-172)
		tmp = cos(M) * exp(-l);
	elseif (n <= 750000.0)
		tmp = t_0;
	else
		tmp = exp((-0.25 * (n ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, -1.5e-247], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 7.8e-237], t$95$0, If[LessEqual[n, 3.7e-172], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 750000.0], t$95$0, N[Exp[N[(-0.25 * N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{-{M}^{2}}\\
\mathbf{if}\;n \leq -1.5 \cdot 10^{-247}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\

\mathbf{elif}\;n \leq 7.8 \cdot 10^{-237}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;n \leq 750000:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if n < -1.4999999999999999e-247

    1. Initial program 76.3%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 96.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-neg96.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. Simplified96.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 m around inf 53.6%

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

    if -1.4999999999999999e-247 < n < 7.7999999999999997e-237 or 3.70000000000000001e-172 < n < 7.5e5

    1. Initial program 87.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 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 M around inf 61.1%

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

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

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

    if 7.7999999999999997e-237 < n < 3.70000000000000001e-172

    1. Initial program 88.9%

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

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

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

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

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

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

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

    if 7.5e5 < n

    1. Initial program 66.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 98.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -1.5 \cdot 10^{-247}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;n \leq 7.8 \cdot 10^{-237}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{elif}\;n \leq 3.7 \cdot 10^{-172}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;n \leq 750000:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot {n}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 74.7% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -31000000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 2.3 \cdot 10^{-184}:\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\

\mathbf{elif}\;M \leq 0.0205:\\
\;\;\;\;\cos \left(\frac{m \cdot K}{2} - M\right) \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\

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


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

    1. Initial program 79.4%

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(-{\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 97.1%

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

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

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

    if -3.1e7 < M < 2.2999999999999999e-184

    1. Initial program 68.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 92.4%

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

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

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

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

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

    if 2.2999999999999999e-184 < M < 0.0205000000000000009

    1. Initial program 92.0%

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

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

      \[\leadsto \cos \left(\frac{K \cdot m}{2} - M\right) \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    5. Step-by-step derivation
      1. unpow252.8%

        \[\leadsto \cos \left(\frac{K \cdot m}{2} - M\right) \cdot e^{-0.25 \cdot \color{blue}{\left(m \cdot m\right)}} \]
    6. Applied egg-rr52.8%

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

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

Alternative 8: 65.3% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.7 \cdot 10^{+23}:\\
\;\;\;\;\cos \left(K \cdot \frac{m}{2} - M\right) \cdot e^{\ell}\\

\mathbf{elif}\;\ell \leq -6 \cdot 10^{-308}:\\
\;\;\;\;\cos \left(\frac{m \cdot K}{2} - M\right) \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;\ell \leq 8.5 \cdot 10^{-12}:\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\

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


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

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(\cos \left(K \cdot \frac{m}{2} - M\right) \cdot e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}\right)}^{1} \]
      7. add-sqr-sqrt63.0%

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

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

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

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

    if -2.6999999999999999e23 < l < -6.00000000000000044e-308

    1. Initial program 86.7%

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

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

      \[\leadsto \cos \left(\frac{K \cdot m}{2} - M\right) \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    5. Step-by-step derivation
      1. unpow254.5%

        \[\leadsto \cos \left(\frac{K \cdot m}{2} - M\right) \cdot e^{-0.25 \cdot \color{blue}{\left(m \cdot m\right)}} \]
    6. Applied egg-rr54.5%

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

    if -6.00000000000000044e-308 < l < 8.4999999999999997e-12

    1. Initial program 66.3%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 94.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-neg94.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. Simplified94.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 inf 55.9%

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

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

    if 8.4999999999999997e-12 < l

    1. Initial program 84.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 l around inf 100.0%

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

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

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

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

Alternative 9: 67.0% accurate, 2.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -1.64999999999999997e-88 or 7.5e5 < n

    1. Initial program 68.7%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 97.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-neg97.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. Simplified97.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 inf 90.7%

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

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

    if -1.64999999999999997e-88 < n < 7.5e5

    1. Initial program 88.3%

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

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

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

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

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

Alternative 10: 68.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.012:\\
\;\;\;\;\cos \left(K \cdot \frac{m}{2} - M\right) \cdot e^{\ell}\\

\mathbf{elif}\;\ell \leq 8.5 \cdot 10^{-12}:\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\

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


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

    1. Initial program 75.7%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    6. Simplified18.6%

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

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

        \[\leadsto {\left(\cos \left(\color{blue}{K \cdot \frac{m}{2}} - M\right) \cdot e^{-\ell}\right)}^{1} \]
      3. add-sqr-sqrt18.6%

        \[\leadsto {\left(\cos \left(K \cdot \frac{m}{2} - M\right) \cdot e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}}\right)}^{1} \]
      4. sqrt-unprod18.6%

        \[\leadsto {\left(\cos \left(K \cdot \frac{m}{2} - M\right) \cdot e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}}\right)}^{1} \]
      5. sqr-neg18.6%

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

        \[\leadsto {\left(\cos \left(K \cdot \frac{m}{2} - M\right) \cdot e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}\right)}^{1} \]
      7. add-sqr-sqrt65.2%

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

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

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

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

    if -0.012 < l < 8.4999999999999997e-12

    1. Initial program 75.4%

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

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

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

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

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

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

    if 8.4999999999999997e-12 < l

    1. Initial program 84.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 l around inf 100.0%

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

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

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

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

Alternative 11: 53.4% accurate, 2.1× speedup?

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

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

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

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

    \[\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 53.6%

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

    \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]
  8. Final simplification53.5%

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

Alternative 12: 7.1% 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 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 96.7%

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

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

    \[\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 53.6%

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

    \[\leadsto \cos M \cdot \color{blue}{1} \]
  8. Final simplification7.4%

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

Reproduce

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