Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.7% → 96.6%
Time: 13.5s
Alternatives: 9
Speedup: 2.7×

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 9 alternatives:

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

Initial Program: 75.7% accurate, 1.0× speedup?

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

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

Alternative 1: 96.6% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \cos M \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 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(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(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(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(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(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(M) * exp((-((((m + n) / 2.0) - M) ^ 2.0) - (l - abs((m - n)))));
end
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $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 M \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}
\end{array}
Derivation
  1. Initial program 75.8%

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

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. lower-cos.f6494.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. Applied rewrites94.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. Add Preprocessing

Alternative 2: 92.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(n + m\right) - M\\ t_1 := \left|m - n\right|\\ t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - t\_1\right)}\\ t_3 := 1 \cdot \left(\left(\left(-\ell\right) + 1\right) \cdot e^{t\_1 - t\_0 \cdot t\_0}\right)\\ \mathbf{if}\;t\_2 \leq 0.8:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;\cos \left(0.5 \cdot \left(\left(n + m\right) \cdot K\right)\right) \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (* 0.5 (+ n m)) M))
        (t_1 (fabs (- m n)))
        (t_2
         (*
          (cos (- (/ (* K (+ m n)) 2.0) M))
          (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l t_1)))))
        (t_3 (* 1.0 (* (+ (- l) 1.0) (exp (- t_1 (* t_0 t_0)))))))
   (if (<= t_2 0.8)
     t_3
     (if (<= t_2 INFINITY) (* (cos (* 0.5 (* (+ n m) K))) (exp (- l))) t_3))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = (0.5 * (n + m)) - M;
	double t_1 = fabs((m - n));
	double t_2 = cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)));
	double t_3 = 1.0 * ((-l + 1.0) * exp((t_1 - (t_0 * t_0))));
	double tmp;
	if (t_2 <= 0.8) {
		tmp = t_3;
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = cos((0.5 * ((n + m) * K))) * exp(-l);
	} else {
		tmp = t_3;
	}
	return tmp;
}
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = (0.5 * (n + m)) - M;
	double t_1 = Math.abs((m - n));
	double t_2 = Math.cos((((K * (m + n)) / 2.0) - M)) * Math.exp((-Math.pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)));
	double t_3 = 1.0 * ((-l + 1.0) * Math.exp((t_1 - (t_0 * t_0))));
	double tmp;
	if (t_2 <= 0.8) {
		tmp = t_3;
	} else if (t_2 <= Double.POSITIVE_INFINITY) {
		tmp = Math.cos((0.5 * ((n + m) * K))) * Math.exp(-l);
	} else {
		tmp = t_3;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = (0.5 * (n + m)) - M
	t_1 = math.fabs((m - n))
	t_2 = math.cos((((K * (m + n)) / 2.0) - M)) * math.exp((-math.pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)))
	t_3 = 1.0 * ((-l + 1.0) * math.exp((t_1 - (t_0 * t_0))))
	tmp = 0
	if t_2 <= 0.8:
		tmp = t_3
	elif t_2 <= math.inf:
		tmp = math.cos((0.5 * ((n + m) * K))) * math.exp(-l)
	else:
		tmp = t_3
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(Float64(0.5 * Float64(n + m)) - M)
	t_1 = abs(Float64(m - n))
	t_2 = 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 - t_1))))
	t_3 = Float64(1.0 * Float64(Float64(Float64(-l) + 1.0) * exp(Float64(t_1 - Float64(t_0 * t_0)))))
	tmp = 0.0
	if (t_2 <= 0.8)
		tmp = t_3;
	elseif (t_2 <= Inf)
		tmp = Float64(cos(Float64(0.5 * Float64(Float64(n + m) * K))) * exp(Float64(-l)));
	else
		tmp = t_3;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = (0.5 * (n + m)) - M;
	t_1 = abs((m - n));
	t_2 = cos((((K * (m + n)) / 2.0) - M)) * exp((-((((m + n) / 2.0) - M) ^ 2.0) - (l - t_1)));
	t_3 = 1.0 * ((-l + 1.0) * exp((t_1 - (t_0 * t_0))));
	tmp = 0.0;
	if (t_2 <= 0.8)
		tmp = t_3;
	elseif (t_2 <= Inf)
		tmp = cos((0.5 * ((n + m) * K))) * exp(-l);
	else
		tmp = t_3;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(0.5 * N[(n + m), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = 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 - t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 * N[(N[((-l) + 1.0), $MachinePrecision] * N[Exp[N[(t$95$1 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, 0.8], t$95$3, If[LessEqual[t$95$2, Infinity], N[(N[Cos[N[(0.5 * N[(N[(n + m), $MachinePrecision] * K), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(n + m\right) - M\\
t_1 := \left|m - n\right|\\
t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - t\_1\right)}\\
t_3 := 1 \cdot \left(\left(\left(-\ell\right) + 1\right) \cdot e^{t\_1 - t\_0 \cdot t\_0}\right)\\
\mathbf{if}\;t\_2 \leq 0.8:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;\cos \left(0.5 \cdot \left(\left(n + m\right) \cdot K\right)\right) \cdot e^{-\ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 0.80000000000000004 or +inf.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

    1. Initial program 74.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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. lower-cos.f6496.1

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
      2. lower-neg.f6427.6

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

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

      \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
    10. Step-by-step derivation
      1. Applied rewrites27.2%

        \[\leadsto 1 \cdot e^{-\ell} \]
      2. Taylor expanded in l around 0

        \[\leadsto 1 \cdot \color{blue}{\left(e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}} + -1 \cdot \left(\ell \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)\right)} \]
      3. Step-by-step derivation
        1. associate-*r*N/A

          \[\leadsto 1 \cdot \left(e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}} + \color{blue}{\left(-1 \cdot \ell\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
        2. distribute-rgt1-inN/A

          \[\leadsto 1 \cdot \color{blue}{\left(\left(-1 \cdot \ell + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)} \]
        3. lower-*.f64N/A

          \[\leadsto 1 \cdot \color{blue}{\left(\left(-1 \cdot \ell + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)} \]
        4. lower-+.f64N/A

          \[\leadsto 1 \cdot \left(\color{blue}{\left(-1 \cdot \ell + 1\right)} \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
        5. mul-1-negN/A

          \[\leadsto 1 \cdot \left(\left(\color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
        6. lower-neg.f64N/A

          \[\leadsto 1 \cdot \left(\left(\color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
        7. lower-exp.f64N/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot \color{blue}{e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
        8. lower--.f64N/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\color{blue}{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
        9. lower-fabs.f64N/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\color{blue}{\left|m - n\right|} - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
        10. lower--.f64N/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|\color{blue}{m - n}\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
        11. unpow2N/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}}\right) \]
        12. lower-*.f64N/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}}\right) \]
        13. lower--.f64N/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)} \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
        14. lower-*.f64N/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \left(\color{blue}{\frac{1}{2} \cdot \left(m + n\right)} - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
        15. +-commutativeN/A

          \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \left(\frac{1}{2} \cdot \color{blue}{\left(n + m\right)} - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
        16. lower-+.f64N/A

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

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

      if 0.80000000000000004 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < +inf.0

      1. Initial program 86.3%

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

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

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
        2. lower-neg.f6486.3

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

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

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right)} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
      7. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right)} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        2. *-commutativeN/A

          \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        3. lower-*.f64N/A

          \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        4. +-commutativeN/A

          \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\right)\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        5. lower-+.f6486.3

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

        \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(\left(n + m\right) \cdot K\right)\right)} \cdot e^{-\ell} \]
    11. Recombined 2 regimes into one program.
    12. Add Preprocessing

    Alternative 3: 92.2% accurate, 0.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(n + m\right) - M\\ t_1 := \left|m - n\right|\\ t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - t\_1\right)}\\ t_3 := 1 \cdot \left(\left(\left(-\ell\right) + 1\right) \cdot e^{t\_1 - t\_0 \cdot t\_0}\right)\\ \mathbf{if}\;t\_2 \leq 0.9:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;\cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
    (FPCore (K m n M l)
     :precision binary64
     (let* ((t_0 (- (* 0.5 (+ n m)) M))
            (t_1 (fabs (- m n)))
            (t_2
             (*
              (cos (- (/ (* K (+ m n)) 2.0) M))
              (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l t_1)))))
            (t_3 (* 1.0 (* (+ (- l) 1.0) (exp (- t_1 (* t_0 t_0)))))))
       (if (<= t_2 0.9)
         t_3
         (if (<= t_2 INFINITY) (* (cos (* 0.5 (* n K))) (exp (- l))) t_3))))
    double code(double K, double m, double n, double M, double l) {
    	double t_0 = (0.5 * (n + m)) - M;
    	double t_1 = fabs((m - n));
    	double t_2 = cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)));
    	double t_3 = 1.0 * ((-l + 1.0) * exp((t_1 - (t_0 * t_0))));
    	double tmp;
    	if (t_2 <= 0.9) {
    		tmp = t_3;
    	} else if (t_2 <= ((double) INFINITY)) {
    		tmp = cos((0.5 * (n * K))) * exp(-l);
    	} else {
    		tmp = t_3;
    	}
    	return tmp;
    }
    
    public static double code(double K, double m, double n, double M, double l) {
    	double t_0 = (0.5 * (n + m)) - M;
    	double t_1 = Math.abs((m - n));
    	double t_2 = Math.cos((((K * (m + n)) / 2.0) - M)) * Math.exp((-Math.pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)));
    	double t_3 = 1.0 * ((-l + 1.0) * Math.exp((t_1 - (t_0 * t_0))));
    	double tmp;
    	if (t_2 <= 0.9) {
    		tmp = t_3;
    	} else if (t_2 <= Double.POSITIVE_INFINITY) {
    		tmp = Math.cos((0.5 * (n * K))) * Math.exp(-l);
    	} else {
    		tmp = t_3;
    	}
    	return tmp;
    }
    
    def code(K, m, n, M, l):
    	t_0 = (0.5 * (n + m)) - M
    	t_1 = math.fabs((m - n))
    	t_2 = math.cos((((K * (m + n)) / 2.0) - M)) * math.exp((-math.pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)))
    	t_3 = 1.0 * ((-l + 1.0) * math.exp((t_1 - (t_0 * t_0))))
    	tmp = 0
    	if t_2 <= 0.9:
    		tmp = t_3
    	elif t_2 <= math.inf:
    		tmp = math.cos((0.5 * (n * K))) * math.exp(-l)
    	else:
    		tmp = t_3
    	return tmp
    
    function code(K, m, n, M, l)
    	t_0 = Float64(Float64(0.5 * Float64(n + m)) - M)
    	t_1 = abs(Float64(m - n))
    	t_2 = 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 - t_1))))
    	t_3 = Float64(1.0 * Float64(Float64(Float64(-l) + 1.0) * exp(Float64(t_1 - Float64(t_0 * t_0)))))
    	tmp = 0.0
    	if (t_2 <= 0.9)
    		tmp = t_3;
    	elseif (t_2 <= Inf)
    		tmp = Float64(cos(Float64(0.5 * Float64(n * K))) * exp(Float64(-l)));
    	else
    		tmp = t_3;
    	end
    	return tmp
    end
    
    function tmp_2 = code(K, m, n, M, l)
    	t_0 = (0.5 * (n + m)) - M;
    	t_1 = abs((m - n));
    	t_2 = cos((((K * (m + n)) / 2.0) - M)) * exp((-((((m + n) / 2.0) - M) ^ 2.0) - (l - t_1)));
    	t_3 = 1.0 * ((-l + 1.0) * exp((t_1 - (t_0 * t_0))));
    	tmp = 0.0;
    	if (t_2 <= 0.9)
    		tmp = t_3;
    	elseif (t_2 <= Inf)
    		tmp = cos((0.5 * (n * K))) * exp(-l);
    	else
    		tmp = t_3;
    	end
    	tmp_2 = tmp;
    end
    
    code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(0.5 * N[(n + m), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = 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 - t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 * N[(N[((-l) + 1.0), $MachinePrecision] * N[Exp[N[(t$95$1 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, 0.9], t$95$3, If[LessEqual[t$95$2, Infinity], N[(N[Cos[N[(0.5 * N[(n * K), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := 0.5 \cdot \left(n + m\right) - M\\
    t_1 := \left|m - n\right|\\
    t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - t\_1\right)}\\
    t_3 := 1 \cdot \left(\left(\left(-\ell\right) + 1\right) \cdot e^{t\_1 - t\_0 \cdot t\_0}\right)\\
    \mathbf{if}\;t\_2 \leq 0.9:\\
    \;\;\;\;t\_3\\
    
    \mathbf{elif}\;t\_2 \leq \infty:\\
    \;\;\;\;\cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot e^{-\ell}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_3\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 0.900000000000000022 or +inf.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

      1. Initial program 74.1%

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

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

          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
        2. lower-cos.f6495.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. Applied rewrites95.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 l around inf

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

          \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
        2. lower-neg.f6427.5

          \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
      8. Applied rewrites27.5%

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

        \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
      10. Step-by-step derivation
        1. Applied rewrites27.0%

          \[\leadsto 1 \cdot e^{-\ell} \]
        2. Taylor expanded in l around 0

          \[\leadsto 1 \cdot \color{blue}{\left(e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}} + -1 \cdot \left(\ell \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)\right)} \]
        3. Step-by-step derivation
          1. associate-*r*N/A

            \[\leadsto 1 \cdot \left(e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}} + \color{blue}{\left(-1 \cdot \ell\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
          2. distribute-rgt1-inN/A

            \[\leadsto 1 \cdot \color{blue}{\left(\left(-1 \cdot \ell + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)} \]
          3. lower-*.f64N/A

            \[\leadsto 1 \cdot \color{blue}{\left(\left(-1 \cdot \ell + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)} \]
          4. lower-+.f64N/A

            \[\leadsto 1 \cdot \left(\color{blue}{\left(-1 \cdot \ell + 1\right)} \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
          5. mul-1-negN/A

            \[\leadsto 1 \cdot \left(\left(\color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
          6. lower-neg.f64N/A

            \[\leadsto 1 \cdot \left(\left(\color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
          7. lower-exp.f64N/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot \color{blue}{e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
          8. lower--.f64N/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\color{blue}{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
          9. lower-fabs.f64N/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\color{blue}{\left|m - n\right|} - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
          10. lower--.f64N/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|\color{blue}{m - n}\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
          11. unpow2N/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}}\right) \]
          12. lower-*.f64N/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}}\right) \]
          13. lower--.f64N/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)} \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
          14. lower-*.f64N/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \left(\color{blue}{\frac{1}{2} \cdot \left(m + n\right)} - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
          15. +-commutativeN/A

            \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \left(\frac{1}{2} \cdot \color{blue}{\left(n + m\right)} - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
          16. lower-+.f64N/A

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

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

        if 0.900000000000000022 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < +inf.0

        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 l around inf

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

            \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
          2. lower-neg.f6489.3

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

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

          \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot n\right)\right)} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        7. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot n\right)\right)} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
          2. *-commutativeN/A

            \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(n \cdot K\right)}\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
          3. lower-*.f6486.9

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

          \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right)\right)} \cdot e^{-\ell} \]
      11. Recombined 2 regimes into one program.
      12. Add Preprocessing

      Alternative 4: 92.2% accurate, 0.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(n + m\right) - M\\ t_1 := \left|m - n\right|\\ t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - t\_1\right)}\\ t_3 := 1 \cdot \left(\left(\left(-\ell\right) + 1\right) \cdot e^{t\_1 - t\_0 \cdot t\_0}\right)\\ \mathbf{if}\;t\_2 \leq 0.9:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
      (FPCore (K m n M l)
       :precision binary64
       (let* ((t_0 (- (* 0.5 (+ n m)) M))
              (t_1 (fabs (- m n)))
              (t_2
               (*
                (cos (- (/ (* K (+ m n)) 2.0) M))
                (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l t_1)))))
              (t_3 (* 1.0 (* (+ (- l) 1.0) (exp (- t_1 (* t_0 t_0)))))))
         (if (<= t_2 0.9) t_3 (if (<= t_2 INFINITY) (* 1.0 (exp (- l))) t_3))))
      double code(double K, double m, double n, double M, double l) {
      	double t_0 = (0.5 * (n + m)) - M;
      	double t_1 = fabs((m - n));
      	double t_2 = cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)));
      	double t_3 = 1.0 * ((-l + 1.0) * exp((t_1 - (t_0 * t_0))));
      	double tmp;
      	if (t_2 <= 0.9) {
      		tmp = t_3;
      	} else if (t_2 <= ((double) INFINITY)) {
      		tmp = 1.0 * exp(-l);
      	} else {
      		tmp = t_3;
      	}
      	return tmp;
      }
      
      public static double code(double K, double m, double n, double M, double l) {
      	double t_0 = (0.5 * (n + m)) - M;
      	double t_1 = Math.abs((m - n));
      	double t_2 = Math.cos((((K * (m + n)) / 2.0) - M)) * Math.exp((-Math.pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)));
      	double t_3 = 1.0 * ((-l + 1.0) * Math.exp((t_1 - (t_0 * t_0))));
      	double tmp;
      	if (t_2 <= 0.9) {
      		tmp = t_3;
      	} else if (t_2 <= Double.POSITIVE_INFINITY) {
      		tmp = 1.0 * Math.exp(-l);
      	} else {
      		tmp = t_3;
      	}
      	return tmp;
      }
      
      def code(K, m, n, M, l):
      	t_0 = (0.5 * (n + m)) - M
      	t_1 = math.fabs((m - n))
      	t_2 = math.cos((((K * (m + n)) / 2.0) - M)) * math.exp((-math.pow((((m + n) / 2.0) - M), 2.0) - (l - t_1)))
      	t_3 = 1.0 * ((-l + 1.0) * math.exp((t_1 - (t_0 * t_0))))
      	tmp = 0
      	if t_2 <= 0.9:
      		tmp = t_3
      	elif t_2 <= math.inf:
      		tmp = 1.0 * math.exp(-l)
      	else:
      		tmp = t_3
      	return tmp
      
      function code(K, m, n, M, l)
      	t_0 = Float64(Float64(0.5 * Float64(n + m)) - M)
      	t_1 = abs(Float64(m - n))
      	t_2 = 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 - t_1))))
      	t_3 = Float64(1.0 * Float64(Float64(Float64(-l) + 1.0) * exp(Float64(t_1 - Float64(t_0 * t_0)))))
      	tmp = 0.0
      	if (t_2 <= 0.9)
      		tmp = t_3;
      	elseif (t_2 <= Inf)
      		tmp = Float64(1.0 * exp(Float64(-l)));
      	else
      		tmp = t_3;
      	end
      	return tmp
      end
      
      function tmp_2 = code(K, m, n, M, l)
      	t_0 = (0.5 * (n + m)) - M;
      	t_1 = abs((m - n));
      	t_2 = cos((((K * (m + n)) / 2.0) - M)) * exp((-((((m + n) / 2.0) - M) ^ 2.0) - (l - t_1)));
      	t_3 = 1.0 * ((-l + 1.0) * exp((t_1 - (t_0 * t_0))));
      	tmp = 0.0;
      	if (t_2 <= 0.9)
      		tmp = t_3;
      	elseif (t_2 <= Inf)
      		tmp = 1.0 * exp(-l);
      	else
      		tmp = t_3;
      	end
      	tmp_2 = tmp;
      end
      
      code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(0.5 * N[(n + m), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = 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 - t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(1.0 * N[(N[((-l) + 1.0), $MachinePrecision] * N[Exp[N[(t$95$1 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, 0.9], t$95$3, If[LessEqual[t$95$2, Infinity], N[(1.0 * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := 0.5 \cdot \left(n + m\right) - M\\
      t_1 := \left|m - n\right|\\
      t_2 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - t\_1\right)}\\
      t_3 := 1 \cdot \left(\left(\left(-\ell\right) + 1\right) \cdot e^{t\_1 - t\_0 \cdot t\_0}\right)\\
      \mathbf{if}\;t\_2 \leq 0.9:\\
      \;\;\;\;t\_3\\
      
      \mathbf{elif}\;t\_2 \leq \infty:\\
      \;\;\;\;1 \cdot e^{-\ell}\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_3\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 0.900000000000000022 or +inf.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

        1. Initial program 74.1%

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

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

            \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
          2. lower-cos.f6495.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. Applied rewrites95.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 l around inf

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

            \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
          2. lower-neg.f6427.5

            \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
        8. Applied rewrites27.5%

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

          \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        10. Step-by-step derivation
          1. Applied rewrites27.0%

            \[\leadsto 1 \cdot e^{-\ell} \]
          2. Taylor expanded in l around 0

            \[\leadsto 1 \cdot \color{blue}{\left(e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}} + -1 \cdot \left(\ell \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)\right)} \]
          3. Step-by-step derivation
            1. associate-*r*N/A

              \[\leadsto 1 \cdot \left(e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}} + \color{blue}{\left(-1 \cdot \ell\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
            2. distribute-rgt1-inN/A

              \[\leadsto 1 \cdot \color{blue}{\left(\left(-1 \cdot \ell + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)} \]
            3. lower-*.f64N/A

              \[\leadsto 1 \cdot \color{blue}{\left(\left(-1 \cdot \ell + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)} \]
            4. lower-+.f64N/A

              \[\leadsto 1 \cdot \left(\color{blue}{\left(-1 \cdot \ell + 1\right)} \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
            5. mul-1-negN/A

              \[\leadsto 1 \cdot \left(\left(\color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
            6. lower-neg.f64N/A

              \[\leadsto 1 \cdot \left(\left(\color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
            7. lower-exp.f64N/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot \color{blue}{e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
            8. lower--.f64N/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\color{blue}{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
            9. lower-fabs.f64N/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\color{blue}{\left|m - n\right|} - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
            10. lower--.f64N/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|\color{blue}{m - n}\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
            11. unpow2N/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}}\right) \]
            12. lower-*.f64N/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}}\right) \]
            13. lower--.f64N/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)} \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
            14. lower-*.f64N/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \left(\color{blue}{\frac{1}{2} \cdot \left(m + n\right)} - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
            15. +-commutativeN/A

              \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \left(\frac{1}{2} \cdot \color{blue}{\left(n + m\right)} - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
            16. lower-+.f64N/A

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

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

          if 0.900000000000000022 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < +inf.0

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

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

              \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
            2. lower-cos.f6486.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. Applied rewrites86.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

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

              \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
            2. lower-neg.f6486.9

              \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
          8. Applied rewrites86.9%

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

            \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
          10. Step-by-step derivation
            1. Applied rewrites86.9%

              \[\leadsto 1 \cdot e^{-\ell} \]
          11. Recombined 2 regimes into one program.
          12. Add Preprocessing

          Alternative 5: 95.2% accurate, 0.5× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(n + m\right) - M\\ t_1 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ t_2 := \left|m - n\right|\\ \mathbf{if}\;t\_1 \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - t\_2\right)} \leq \infty:\\ \;\;\;\;t\_1 \cdot e^{M \cdot \mathsf{fma}\left(M, \frac{\frac{\left|n - m\right| - \mathsf{fma}\left(0.25 \cdot \left(n + m\right), n + m, \ell\right)}{M} + \left(n + m\right)}{M}, -M\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\left(\left(-\ell\right) + 1\right) \cdot e^{t\_2 - t\_0 \cdot t\_0}\right)\\ \end{array} \end{array} \]
          (FPCore (K m n M l)
           :precision binary64
           (let* ((t_0 (- (* 0.5 (+ n m)) M))
                  (t_1 (cos (- (/ (* K (+ m n)) 2.0) M)))
                  (t_2 (fabs (- m n))))
             (if (<=
                  (* t_1 (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l t_2))))
                  INFINITY)
               (*
                t_1
                (exp
                 (*
                  M
                  (fma
                   M
                   (/
                    (+ (/ (- (fabs (- n m)) (fma (* 0.25 (+ n m)) (+ n m) l)) M) (+ n m))
                    M)
                   (- M)))))
               (* 1.0 (* (+ (- l) 1.0) (exp (- t_2 (* t_0 t_0))))))))
          double code(double K, double m, double n, double M, double l) {
          	double t_0 = (0.5 * (n + m)) - M;
          	double t_1 = cos((((K * (m + n)) / 2.0) - M));
          	double t_2 = fabs((m - n));
          	double tmp;
          	if ((t_1 * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - t_2)))) <= ((double) INFINITY)) {
          		tmp = t_1 * exp((M * fma(M, ((((fabs((n - m)) - fma((0.25 * (n + m)), (n + m), l)) / M) + (n + m)) / M), -M)));
          	} else {
          		tmp = 1.0 * ((-l + 1.0) * exp((t_2 - (t_0 * t_0))));
          	}
          	return tmp;
          }
          
          function code(K, m, n, M, l)
          	t_0 = Float64(Float64(0.5 * Float64(n + m)) - M)
          	t_1 = cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M))
          	t_2 = abs(Float64(m - n))
          	tmp = 0.0
          	if (Float64(t_1 * exp(Float64(Float64(-(Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)) - Float64(l - t_2)))) <= Inf)
          		tmp = Float64(t_1 * exp(Float64(M * fma(M, Float64(Float64(Float64(Float64(abs(Float64(n - m)) - fma(Float64(0.25 * Float64(n + m)), Float64(n + m), l)) / M) + Float64(n + m)) / M), Float64(-M)))));
          	else
          		tmp = Float64(1.0 * Float64(Float64(Float64(-l) + 1.0) * exp(Float64(t_2 - Float64(t_0 * t_0)))));
          	end
          	return tmp
          end
          
          code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(0.5 * N[(n + m), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$1 * N[Exp[N[((-N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]) - N[(l - t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], Infinity], N[(t$95$1 * N[Exp[N[(M * N[(M * N[(N[(N[(N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - N[(N[(0.25 * N[(n + m), $MachinePrecision]), $MachinePrecision] * N[(n + m), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] + N[(n + m), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] + (-M)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 * N[(N[((-l) + 1.0), $MachinePrecision] * N[Exp[N[(t$95$2 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := 0.5 \cdot \left(n + m\right) - M\\
          t_1 := \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
          t_2 := \left|m - n\right|\\
          \mathbf{if}\;t\_1 \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - t\_2\right)} \leq \infty:\\
          \;\;\;\;t\_1 \cdot e^{M \cdot \mathsf{fma}\left(M, \frac{\frac{\left|n - m\right| - \mathsf{fma}\left(0.25 \cdot \left(n + m\right), n + m, \ell\right)}{M} + \left(n + m\right)}{M}, -M\right)}\\
          
          \mathbf{else}:\\
          \;\;\;\;1 \cdot \left(\left(\left(-\ell\right) + 1\right) \cdot e^{t\_2 - t\_0 \cdot t\_0}\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < +inf.0

            1. Initial program 94.2%

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

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

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

            if +inf.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

            1. Initial program 0.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

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

                \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
              2. lower-cos.f64100.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. Applied rewrites100.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

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

                \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
              2. lower-neg.f6433.9

                \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
            8. Applied rewrites33.9%

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

              \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
            10. Step-by-step derivation
              1. Applied rewrites33.9%

                \[\leadsto 1 \cdot e^{-\ell} \]
              2. Taylor expanded in l around 0

                \[\leadsto 1 \cdot \color{blue}{\left(e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}} + -1 \cdot \left(\ell \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)\right)} \]
              3. Step-by-step derivation
                1. associate-*r*N/A

                  \[\leadsto 1 \cdot \left(e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}} + \color{blue}{\left(-1 \cdot \ell\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
                2. distribute-rgt1-inN/A

                  \[\leadsto 1 \cdot \color{blue}{\left(\left(-1 \cdot \ell + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)} \]
                3. lower-*.f64N/A

                  \[\leadsto 1 \cdot \color{blue}{\left(\left(-1 \cdot \ell + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right)} \]
                4. lower-+.f64N/A

                  \[\leadsto 1 \cdot \left(\color{blue}{\left(-1 \cdot \ell + 1\right)} \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
                5. mul-1-negN/A

                  \[\leadsto 1 \cdot \left(\left(\color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
                6. lower-neg.f64N/A

                  \[\leadsto 1 \cdot \left(\left(\color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} + 1\right) \cdot e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
                7. lower-exp.f64N/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot \color{blue}{e^{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
                8. lower--.f64N/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\color{blue}{\left|m - n\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}}\right) \]
                9. lower-fabs.f64N/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\color{blue}{\left|m - n\right|} - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
                10. lower--.f64N/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|\color{blue}{m - n}\right| - {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}}\right) \]
                11. unpow2N/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}}\right) \]
                12. lower-*.f64N/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}}\right) \]
                13. lower--.f64N/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \color{blue}{\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)} \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
                14. lower-*.f64N/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \left(\color{blue}{\frac{1}{2} \cdot \left(m + n\right)} - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
                15. +-commutativeN/A

                  \[\leadsto 1 \cdot \left(\left(\left(\mathsf{neg}\left(\ell\right)\right) + 1\right) \cdot e^{\left|m - n\right| - \left(\frac{1}{2} \cdot \color{blue}{\left(n + m\right)} - M\right) \cdot \left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}\right) \]
                16. lower-+.f64N/A

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

                \[\leadsto 1 \cdot \color{blue}{\left(\left(\left(-\ell\right) + 1\right) \cdot e^{\left|m - n\right| - \left(0.5 \cdot \left(n + m\right) - M\right) \cdot \left(0.5 \cdot \left(n + m\right) - M\right)}\right)} \]
            11. Recombined 2 regimes into one program.
            12. Add Preprocessing

            Alternative 6: 76.0% accurate, 2.7× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -1000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 6.8 \cdot 10^{-44}:\\ \;\;\;\;1 \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;M \leq 26.5:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
            (FPCore (K m n M l)
             :precision binary64
             (let* ((t_0 (* 1.0 (exp (* M (- M))))))
               (if (<= M -1000000.0)
                 t_0
                 (if (<= M 6.8e-44)
                   (* 1.0 (exp (* (* m m) -0.25)))
                   (if (<= M 26.5) (* 1.0 (exp (- l))) t_0)))))
            double code(double K, double m, double n, double M, double l) {
            	double t_0 = 1.0 * exp((M * -M));
            	double tmp;
            	if (M <= -1000000.0) {
            		tmp = t_0;
            	} else if (M <= 6.8e-44) {
            		tmp = 1.0 * exp(((m * m) * -0.25));
            	} else if (M <= 26.5) {
            		tmp = 1.0 * exp(-l);
            	} 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 = 1.0d0 * exp((m_1 * -m_1))
                if (m_1 <= (-1000000.0d0)) then
                    tmp = t_0
                else if (m_1 <= 6.8d-44) then
                    tmp = 1.0d0 * exp(((m * m) * (-0.25d0)))
                else if (m_1 <= 26.5d0) then
                    tmp = 1.0d0 * exp(-l)
                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 = 1.0 * Math.exp((M * -M));
            	double tmp;
            	if (M <= -1000000.0) {
            		tmp = t_0;
            	} else if (M <= 6.8e-44) {
            		tmp = 1.0 * Math.exp(((m * m) * -0.25));
            	} else if (M <= 26.5) {
            		tmp = 1.0 * Math.exp(-l);
            	} else {
            		tmp = t_0;
            	}
            	return tmp;
            }
            
            def code(K, m, n, M, l):
            	t_0 = 1.0 * math.exp((M * -M))
            	tmp = 0
            	if M <= -1000000.0:
            		tmp = t_0
            	elif M <= 6.8e-44:
            		tmp = 1.0 * math.exp(((m * m) * -0.25))
            	elif M <= 26.5:
            		tmp = 1.0 * math.exp(-l)
            	else:
            		tmp = t_0
            	return tmp
            
            function code(K, m, n, M, l)
            	t_0 = Float64(1.0 * exp(Float64(M * Float64(-M))))
            	tmp = 0.0
            	if (M <= -1000000.0)
            		tmp = t_0;
            	elseif (M <= 6.8e-44)
            		tmp = Float64(1.0 * exp(Float64(Float64(m * m) * -0.25)));
            	elseif (M <= 26.5)
            		tmp = Float64(1.0 * exp(Float64(-l)));
            	else
            		tmp = t_0;
            	end
            	return tmp
            end
            
            function tmp_2 = code(K, m, n, M, l)
            	t_0 = 1.0 * exp((M * -M));
            	tmp = 0.0;
            	if (M <= -1000000.0)
            		tmp = t_0;
            	elseif (M <= 6.8e-44)
            		tmp = 1.0 * exp(((m * m) * -0.25));
            	elseif (M <= 26.5)
            		tmp = 1.0 * exp(-l);
            	else
            		tmp = t_0;
            	end
            	tmp_2 = tmp;
            end
            
            code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(1.0 * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -1000000.0], t$95$0, If[LessEqual[M, 6.8e-44], N[(1.0 * N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 26.5], N[(1.0 * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := 1 \cdot e^{M \cdot \left(-M\right)}\\
            \mathbf{if}\;M \leq -1000000:\\
            \;\;\;\;t\_0\\
            
            \mathbf{elif}\;M \leq 6.8 \cdot 10^{-44}:\\
            \;\;\;\;1 \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\
            
            \mathbf{elif}\;M \leq 26.5:\\
            \;\;\;\;1 \cdot e^{-\ell}\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_0\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if M < -1e6 or 26.5 < M

              1. Initial program 83.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

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

                  \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                2. lower-cos.f64100.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. Applied rewrites100.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

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

                  \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                2. lower-neg.f6425.1

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

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

                \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
              10. Step-by-step derivation
                1. Applied rewrites24.3%

                  \[\leadsto 1 \cdot e^{-\ell} \]
                2. Taylor expanded in M around inf

                  \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
                3. Step-by-step derivation
                  1. mul-1-negN/A

                    \[\leadsto 1 \cdot e^{\color{blue}{\mathsf{neg}\left({M}^{2}\right)}} \]
                  2. unpow2N/A

                    \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\color{blue}{M \cdot M}\right)} \]
                  3. distribute-rgt-neg-inN/A

                    \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(\mathsf{neg}\left(M\right)\right)}} \]
                  4. lower-*.f64N/A

                    \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(\mathsf{neg}\left(M\right)\right)}} \]
                  5. lower-neg.f6499.2

                    \[\leadsto 1 \cdot e^{M \cdot \color{blue}{\left(-M\right)}} \]
                4. Applied rewrites99.2%

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

                if -1e6 < M < 6.80000000000000033e-44

                1. Initial program 67.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

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

                    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                  2. lower-cos.f6490.1

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

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

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

                    \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                  2. lower-neg.f6438.1

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

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

                  \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                10. Step-by-step derivation
                  1. Applied rewrites38.1%

                    \[\leadsto 1 \cdot e^{-\ell} \]
                  2. Taylor expanded in m around inf

                    \[\leadsto 1 \cdot e^{\color{blue}{\frac{-1}{4} \cdot {m}^{2}}} \]
                  3. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot \frac{-1}{4}}} \]
                    2. lower-*.f64N/A

                      \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot \frac{-1}{4}}} \]
                    3. unpow2N/A

                      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot \frac{-1}{4}} \]
                    4. lower-*.f6452.3

                      \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
                  4. Applied rewrites52.3%

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

                  if 6.80000000000000033e-44 < M < 26.5

                  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

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

                      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                    2. lower-cos.f6492.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. Applied rewrites92.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

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

                      \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                    2. lower-neg.f6476.8

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

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

                    \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                  10. Step-by-step derivation
                    1. Applied rewrites76.8%

                      \[\leadsto 1 \cdot e^{-\ell} \]
                  11. Recombined 3 regimes into one program.
                  12. Add Preprocessing

                  Alternative 7: 65.9% accurate, 2.8× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 4.4 \cdot 10^{-203}:\\ \;\;\;\;1 \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;n \leq 450:\\ \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \end{array} \]
                  (FPCore (K m n M l)
                   :precision binary64
                   (if (<= n 4.4e-203)
                     (* 1.0 (exp (* (* m m) -0.25)))
                     (if (<= n 450.0)
                       (* 1.0 (exp (* M (- M))))
                       (* 1.0 (exp (* (* n n) -0.25))))))
                  double code(double K, double m, double n, double M, double l) {
                  	double tmp;
                  	if (n <= 4.4e-203) {
                  		tmp = 1.0 * exp(((m * m) * -0.25));
                  	} else if (n <= 450.0) {
                  		tmp = 1.0 * exp((M * -M));
                  	} else {
                  		tmp = 1.0 * exp(((n * n) * -0.25));
                  	}
                  	return tmp;
                  }
                  
                  real(8) function code(k, m, n, m_1, l)
                      real(8), intent (in) :: k
                      real(8), intent (in) :: m
                      real(8), intent (in) :: n
                      real(8), intent (in) :: m_1
                      real(8), intent (in) :: l
                      real(8) :: tmp
                      if (n <= 4.4d-203) then
                          tmp = 1.0d0 * exp(((m * m) * (-0.25d0)))
                      else if (n <= 450.0d0) then
                          tmp = 1.0d0 * exp((m_1 * -m_1))
                      else
                          tmp = 1.0d0 * exp(((n * n) * (-0.25d0)))
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double K, double m, double n, double M, double l) {
                  	double tmp;
                  	if (n <= 4.4e-203) {
                  		tmp = 1.0 * Math.exp(((m * m) * -0.25));
                  	} else if (n <= 450.0) {
                  		tmp = 1.0 * Math.exp((M * -M));
                  	} else {
                  		tmp = 1.0 * Math.exp(((n * n) * -0.25));
                  	}
                  	return tmp;
                  }
                  
                  def code(K, m, n, M, l):
                  	tmp = 0
                  	if n <= 4.4e-203:
                  		tmp = 1.0 * math.exp(((m * m) * -0.25))
                  	elif n <= 450.0:
                  		tmp = 1.0 * math.exp((M * -M))
                  	else:
                  		tmp = 1.0 * math.exp(((n * n) * -0.25))
                  	return tmp
                  
                  function code(K, m, n, M, l)
                  	tmp = 0.0
                  	if (n <= 4.4e-203)
                  		tmp = Float64(1.0 * exp(Float64(Float64(m * m) * -0.25)));
                  	elseif (n <= 450.0)
                  		tmp = Float64(1.0 * exp(Float64(M * Float64(-M))));
                  	else
                  		tmp = Float64(1.0 * exp(Float64(Float64(n * n) * -0.25)));
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(K, m, n, M, l)
                  	tmp = 0.0;
                  	if (n <= 4.4e-203)
                  		tmp = 1.0 * exp(((m * m) * -0.25));
                  	elseif (n <= 450.0)
                  		tmp = 1.0 * exp((M * -M));
                  	else
                  		tmp = 1.0 * exp(((n * n) * -0.25));
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[K_, m_, n_, M_, l_] := If[LessEqual[n, 4.4e-203], N[(1.0 * N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 450.0], N[(1.0 * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 * N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;n \leq 4.4 \cdot 10^{-203}:\\
                  \;\;\;\;1 \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\
                  
                  \mathbf{elif}\;n \leq 450:\\
                  \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;1 \cdot e^{\left(n \cdot n\right) \cdot -0.25}\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if n < 4.3999999999999999e-203

                    1. Initial program 75.8%

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

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

                        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                      2. lower-cos.f6492.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. Applied rewrites92.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

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

                        \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                      2. lower-neg.f6434.6

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

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

                      \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                    10. Step-by-step derivation
                      1. Applied rewrites33.9%

                        \[\leadsto 1 \cdot e^{-\ell} \]
                      2. Taylor expanded in m around inf

                        \[\leadsto 1 \cdot e^{\color{blue}{\frac{-1}{4} \cdot {m}^{2}}} \]
                      3. Step-by-step derivation
                        1. *-commutativeN/A

                          \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot \frac{-1}{4}}} \]
                        2. lower-*.f64N/A

                          \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot \frac{-1}{4}}} \]
                        3. unpow2N/A

                          \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot \frac{-1}{4}} \]
                        4. lower-*.f6450.9

                          \[\leadsto 1 \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
                      4. Applied rewrites50.9%

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

                      if 4.3999999999999999e-203 < n < 450

                      1. Initial program 91.7%

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

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

                          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                        2. lower-cos.f6496.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. Applied rewrites96.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 l around inf

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

                          \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                        2. lower-neg.f6435.5

                          \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
                      8. Applied rewrites35.5%

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

                        \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                      10. Step-by-step derivation
                        1. Applied rewrites35.5%

                          \[\leadsto 1 \cdot e^{-\ell} \]
                        2. Taylor expanded in M around inf

                          \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
                        3. Step-by-step derivation
                          1. mul-1-negN/A

                            \[\leadsto 1 \cdot e^{\color{blue}{\mathsf{neg}\left({M}^{2}\right)}} \]
                          2. unpow2N/A

                            \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\color{blue}{M \cdot M}\right)} \]
                          3. distribute-rgt-neg-inN/A

                            \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(\mathsf{neg}\left(M\right)\right)}} \]
                          4. lower-*.f64N/A

                            \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(\mathsf{neg}\left(M\right)\right)}} \]
                          5. lower-neg.f6468.0

                            \[\leadsto 1 \cdot e^{M \cdot \color{blue}{\left(-M\right)}} \]
                        4. Applied rewrites68.0%

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

                        if 450 < n

                        1. Initial program 61.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

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

                            \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                          2. lower-cos.f64100.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. Applied rewrites100.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

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

                            \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                          2. lower-neg.f6431.1

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

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

                          \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                        10. Step-by-step derivation
                          1. Applied rewrites31.1%

                            \[\leadsto 1 \cdot e^{-\ell} \]
                          2. Taylor expanded in n around inf

                            \[\leadsto 1 \cdot e^{\color{blue}{\frac{-1}{4} \cdot {n}^{2}}} \]
                          3. Step-by-step derivation
                            1. *-commutativeN/A

                              \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot \frac{-1}{4}}} \]
                            2. lower-*.f64N/A

                              \[\leadsto 1 \cdot e^{\color{blue}{{n}^{2} \cdot \frac{-1}{4}}} \]
                            3. unpow2N/A

                              \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
                            4. lower-*.f6498.2

                              \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
                          4. Applied rewrites98.2%

                            \[\leadsto 1 \cdot e^{\color{blue}{\left(n \cdot n\right) \cdot -0.25}} \]
                        11. Recombined 3 regimes into one program.
                        12. Add Preprocessing

                        Alternative 8: 69.4% accurate, 2.9× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -3.25 \cdot 10^{-9}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 26.5:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                        (FPCore (K m n M l)
                         :precision binary64
                         (let* ((t_0 (* 1.0 (exp (* M (- M))))))
                           (if (<= M -3.25e-9) t_0 (if (<= M 26.5) (* 1.0 (exp (- l))) t_0))))
                        double code(double K, double m, double n, double M, double l) {
                        	double t_0 = 1.0 * exp((M * -M));
                        	double tmp;
                        	if (M <= -3.25e-9) {
                        		tmp = t_0;
                        	} else if (M <= 26.5) {
                        		tmp = 1.0 * exp(-l);
                        	} 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 = 1.0d0 * exp((m_1 * -m_1))
                            if (m_1 <= (-3.25d-9)) then
                                tmp = t_0
                            else if (m_1 <= 26.5d0) then
                                tmp = 1.0d0 * exp(-l)
                            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 = 1.0 * Math.exp((M * -M));
                        	double tmp;
                        	if (M <= -3.25e-9) {
                        		tmp = t_0;
                        	} else if (M <= 26.5) {
                        		tmp = 1.0 * Math.exp(-l);
                        	} else {
                        		tmp = t_0;
                        	}
                        	return tmp;
                        }
                        
                        def code(K, m, n, M, l):
                        	t_0 = 1.0 * math.exp((M * -M))
                        	tmp = 0
                        	if M <= -3.25e-9:
                        		tmp = t_0
                        	elif M <= 26.5:
                        		tmp = 1.0 * math.exp(-l)
                        	else:
                        		tmp = t_0
                        	return tmp
                        
                        function code(K, m, n, M, l)
                        	t_0 = Float64(1.0 * exp(Float64(M * Float64(-M))))
                        	tmp = 0.0
                        	if (M <= -3.25e-9)
                        		tmp = t_0;
                        	elseif (M <= 26.5)
                        		tmp = Float64(1.0 * exp(Float64(-l)));
                        	else
                        		tmp = t_0;
                        	end
                        	return tmp
                        end
                        
                        function tmp_2 = code(K, m, n, M, l)
                        	t_0 = 1.0 * exp((M * -M));
                        	tmp = 0.0;
                        	if (M <= -3.25e-9)
                        		tmp = t_0;
                        	elseif (M <= 26.5)
                        		tmp = 1.0 * exp(-l);
                        	else
                        		tmp = t_0;
                        	end
                        	tmp_2 = tmp;
                        end
                        
                        code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(1.0 * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -3.25e-9], t$95$0, If[LessEqual[M, 26.5], N[(1.0 * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], t$95$0]]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        t_0 := 1 \cdot e^{M \cdot \left(-M\right)}\\
                        \mathbf{if}\;M \leq -3.25 \cdot 10^{-9}:\\
                        \;\;\;\;t\_0\\
                        
                        \mathbf{elif}\;M \leq 26.5:\\
                        \;\;\;\;1 \cdot e^{-\ell}\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;t\_0\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if M < -3.2500000000000002e-9 or 26.5 < M

                          1. Initial program 83.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

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

                              \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                            2. lower-cos.f64100.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. Applied rewrites100.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

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

                              \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                            2. lower-neg.f6424.6

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

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

                            \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                          10. Step-by-step derivation
                            1. Applied rewrites23.7%

                              \[\leadsto 1 \cdot e^{-\ell} \]
                            2. Taylor expanded in M around inf

                              \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
                            3. Step-by-step derivation
                              1. mul-1-negN/A

                                \[\leadsto 1 \cdot e^{\color{blue}{\mathsf{neg}\left({M}^{2}\right)}} \]
                              2. unpow2N/A

                                \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\color{blue}{M \cdot M}\right)} \]
                              3. distribute-rgt-neg-inN/A

                                \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(\mathsf{neg}\left(M\right)\right)}} \]
                              4. lower-*.f64N/A

                                \[\leadsto 1 \cdot e^{\color{blue}{M \cdot \left(\mathsf{neg}\left(M\right)\right)}} \]
                              5. lower-neg.f6497.6

                                \[\leadsto 1 \cdot e^{M \cdot \color{blue}{\left(-M\right)}} \]
                            4. Applied rewrites97.6%

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

                            if -3.2500000000000002e-9 < M < 26.5

                            1. Initial program 69.2%

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

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

                                \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                              2. lower-cos.f6490.1

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

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

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

                                \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                              2. lower-neg.f6442.3

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

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

                              \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                            10. Step-by-step derivation
                              1. Applied rewrites42.3%

                                \[\leadsto 1 \cdot e^{-\ell} \]
                            11. Recombined 2 regimes into one program.
                            12. Add Preprocessing

                            Alternative 9: 34.8% accurate, 3.3× speedup?

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

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

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

                                \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                              2. lower-cos.f6494.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. Applied rewrites94.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 l around inf

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

                                \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                              2. lower-neg.f6434.0

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

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

                              \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                            10. Step-by-step derivation
                              1. Applied rewrites33.6%

                                \[\leadsto 1 \cdot e^{-\ell} \]
                              2. Add Preprocessing

                              Reproduce

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