Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.7% → 96.6%
Time: 13.2s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 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, 0.3× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\ t_2 := t\_1 \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ t_3 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \mathbf{if}\;t\_2 \leq -0.2:\\ \;\;\;\;\cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \frac{2}{n}\right)} - M\right) \cdot e^{-\ell}\\ \mathbf{elif}\;t\_2 \leq 0.9705712466018273:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;t\_1 \cdot \mathsf{fma}\left(0.5, K \cdot \left(M \cdot \left(m + n\right)\right), 1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (fabs (- m n)) l))
        (t_1 (exp (- t_0 (pow (- (/ (+ m n) 2.0) M) 2.0))))
        (t_2 (* t_1 (cos (- (/ (* K (+ m n)) 2.0) M))))
        (t_3
         (*
          (exp
           (-
            t_0
            (*
             M
             (fma
              M
              (/ (+ n (fma -0.25 (/ (* (+ m n) (+ m n)) M) m)) (- M))
              M))))
          1.0)))
   (if (<= t_2 -0.2)
     (* (cos (- (/ K (fma (/ m (* n n)) -2.0 (/ 2.0 n))) M)) (exp (- l)))
     (if (<= t_2 0.9705712466018273)
       t_3
       (if (<= t_2 INFINITY) (* t_1 (fma 0.5 (* K (* M (+ m n))) 1.0)) t_3)))))
assert(K < m && m < n && n < M && M < l);
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n)) - l;
	double t_1 = exp((t_0 - pow((((m + n) / 2.0) - M), 2.0)));
	double t_2 = t_1 * cos((((K * (m + n)) / 2.0) - M));
	double t_3 = exp((t_0 - (M * fma(M, ((n + fma(-0.25, (((m + n) * (m + n)) / M), m)) / -M), M)))) * 1.0;
	double tmp;
	if (t_2 <= -0.2) {
		tmp = cos(((K / fma((m / (n * n)), -2.0, (2.0 / n))) - M)) * exp(-l);
	} else if (t_2 <= 0.9705712466018273) {
		tmp = t_3;
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = t_1 * fma(0.5, (K * (M * (m + n))), 1.0);
	} else {
		tmp = t_3;
	}
	return tmp;
}
K, m, n, M, l = sort([K, m, n, M, l])
function code(K, m, n, M, l)
	t_0 = Float64(abs(Float64(m - n)) - l)
	t_1 = exp(Float64(t_0 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))
	t_2 = Float64(t_1 * cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)))
	t_3 = Float64(exp(Float64(t_0 - Float64(M * fma(M, Float64(Float64(n + fma(-0.25, Float64(Float64(Float64(m + n) * Float64(m + n)) / M), m)) / Float64(-M)), M)))) * 1.0)
	tmp = 0.0
	if (t_2 <= -0.2)
		tmp = Float64(cos(Float64(Float64(K / fma(Float64(m / Float64(n * n)), -2.0, Float64(2.0 / n))) - M)) * exp(Float64(-l)));
	elseif (t_2 <= 0.9705712466018273)
		tmp = t_3;
	elseif (t_2 <= Inf)
		tmp = Float64(t_1 * fma(0.5, Float64(K * Float64(M * Float64(m + n))), 1.0));
	else
		tmp = t_3;
	end
	return tmp
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(t$95$0 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Exp[N[(t$95$0 - N[(M * N[(M * N[(N[(n + N[(-0.25 * N[(N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] + m), $MachinePrecision]), $MachinePrecision] / (-M)), $MachinePrecision] + M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]}, If[LessEqual[t$95$2, -0.2], N[(N[Cos[N[(N[(K / N[(N[(m / N[(n * n), $MachinePrecision]), $MachinePrecision] * -2.0 + N[(2.0 / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.9705712466018273], t$95$3, If[LessEqual[t$95$2, Infinity], N[(t$95$1 * N[(0.5 * N[(K * N[(M * N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]]
\begin{array}{l}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
\\
\begin{array}{l}
t_0 := \left|m - n\right| - \ell\\
t_1 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
t_2 := t\_1 \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
t_3 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\
\mathbf{if}\;t\_2 \leq -0.2:\\
\;\;\;\;\cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \frac{2}{n}\right)} - M\right) \cdot e^{-\ell}\\

\mathbf{elif}\;t\_2 \leq 0.9705712466018273:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;t\_1 \cdot \mathsf{fma}\left(0.5, K \cdot \left(M \cdot \left(m + n\right)\right), 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 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.20000000000000001

    1. Initial program 39.0%

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

      \[\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.f6439.0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(\frac{K}{\color{blue}{\frac{2}{n + m}}} - M\right) \cdot e^{-\ell} \]
      11. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{\color{blue}{n \cdot n}}, -2, 2 \cdot \frac{1}{n}\right)} - M\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
      6. associate-*r/N/A

        \[\leadsto \cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \color{blue}{\frac{2 \cdot 1}{n}}\right)} - M\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
      7. metadata-evalN/A

        \[\leadsto \cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \frac{\color{blue}{2}}{n}\right)} - M\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
      8. lower-/.f6440.9

        \[\leadsto \cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \color{blue}{\frac{2}{n}}\right)} - M\right) \cdot e^{-\ell} \]
    10. Applied rewrites40.9%

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

    if -0.20000000000000001 < (*.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.97057124660182725 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 76.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^{\left(\mathsf{neg}\left(\color{blue}{{M}^{2} \cdot \left(1 + -1 \cdot \frac{m + \left(n + \frac{-1}{4} \cdot \frac{{\left(m + n\right)}^{2}}{M}\right)}{M}\right)}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    8. Applied rewrites98.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    9. Taylor expanded in M around 0

      \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    10. Step-by-step derivation
      1. Applied rewrites98.0%

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

      if 0.97057124660182725 < (*.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.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}{\left(\cos \left(\mathsf{neg}\left(M\right)\right) + \frac{-1}{2} \cdot \left(K \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\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. +-commutativeN/A

          \[\leadsto \color{blue}{\left(\frac{-1}{2} \cdot \left(K \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right) + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
        2. associate-*r*N/A

          \[\leadsto \left(\color{blue}{\left(\frac{-1}{2} \cdot K\right) \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)} + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
        3. *-commutativeN/A

          \[\leadsto \left(\color{blue}{\left(K \cdot \frac{-1}{2}\right)} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right) + \cos \left(\mathsf{neg}\left(M\right)\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. associate-*l*N/A

          \[\leadsto \left(\color{blue}{K \cdot \left(\frac{-1}{2} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right)} + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
        5. metadata-evalN/A

          \[\leadsto \left(K \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right) + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
        6. distribute-lft-neg-inN/A

          \[\leadsto \left(K \cdot \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right)\right)} + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
        7. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(K, \mathsf{neg}\left(\frac{1}{2} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right), \cos \left(\mathsf{neg}\left(M\right)\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)} \]
      5. Applied rewrites96.6%

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

        \[\leadsto \left(1 + \color{blue}{\frac{1}{2} \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\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)} \]
      7. Step-by-step derivation
        1. Applied rewrites96.6%

          \[\leadsto \mathsf{fma}\left(0.5, \color{blue}{\left(M \cdot \left(n + m\right)\right) \cdot K}, 1\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      8. Recombined 3 regimes into one program.
      9. Final simplification95.3%

        \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq -0.2:\\ \;\;\;\;\cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \frac{2}{n}\right)} - M\right) \cdot e^{-\ell}\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq 0.9705712466018273:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq \infty:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \mathsf{fma}\left(0.5, K \cdot \left(M \cdot \left(m + n\right)\right), 1\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \end{array} \]
      10. Add Preprocessing

      Alternative 2: 96.9% accurate, 0.3× speedup?

      \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := \left|m - n\right| - \ell\\ t_2 := e^{t\_1 - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ t_3 := e^{t\_1 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \mathbf{if}\;t\_2 \leq -0.2:\\ \;\;\;\;\cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \frac{2}{n}\right)} - M\right) \cdot t\_0\\ \mathbf{elif}\;t\_2 \leq 0:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;t\_0 \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
      NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
      (FPCore (K m n M l)
       :precision binary64
       (let* ((t_0 (exp (- l)))
              (t_1 (- (fabs (- m n)) l))
              (t_2
               (*
                (exp (- t_1 (pow (- (/ (+ m n) 2.0) M) 2.0)))
                (cos (- (/ (* K (+ m n)) 2.0) M))))
              (t_3
               (*
                (exp
                 (-
                  t_1
                  (*
                   M
                   (fma
                    M
                    (/ (+ n (fma -0.25 (/ (* (+ m n) (+ m n)) M) m)) (- M))
                    M))))
                1.0)))
         (if (<= t_2 -0.2)
           (* (cos (- (/ K (fma (/ m (* n n)) -2.0 (/ 2.0 n))) M)) t_0)
           (if (<= t_2 0.0)
             t_3
             (if (<= t_2 INFINITY) (* t_0 (cos (- (/ K (/ 2.0 m)) M))) t_3)))))
      assert(K < m && m < n && n < M && M < l);
      double code(double K, double m, double n, double M, double l) {
      	double t_0 = exp(-l);
      	double t_1 = fabs((m - n)) - l;
      	double t_2 = exp((t_1 - pow((((m + n) / 2.0) - M), 2.0))) * cos((((K * (m + n)) / 2.0) - M));
      	double t_3 = exp((t_1 - (M * fma(M, ((n + fma(-0.25, (((m + n) * (m + n)) / M), m)) / -M), M)))) * 1.0;
      	double tmp;
      	if (t_2 <= -0.2) {
      		tmp = cos(((K / fma((m / (n * n)), -2.0, (2.0 / n))) - M)) * t_0;
      	} else if (t_2 <= 0.0) {
      		tmp = t_3;
      	} else if (t_2 <= ((double) INFINITY)) {
      		tmp = t_0 * cos(((K / (2.0 / m)) - M));
      	} else {
      		tmp = t_3;
      	}
      	return tmp;
      }
      
      K, m, n, M, l = sort([K, m, n, M, l])
      function code(K, m, n, M, l)
      	t_0 = exp(Float64(-l))
      	t_1 = Float64(abs(Float64(m - n)) - l)
      	t_2 = Float64(exp(Float64(t_1 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))) * cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)))
      	t_3 = Float64(exp(Float64(t_1 - Float64(M * fma(M, Float64(Float64(n + fma(-0.25, Float64(Float64(Float64(m + n) * Float64(m + n)) / M), m)) / Float64(-M)), M)))) * 1.0)
      	tmp = 0.0
      	if (t_2 <= -0.2)
      		tmp = Float64(cos(Float64(Float64(K / fma(Float64(m / Float64(n * n)), -2.0, Float64(2.0 / n))) - M)) * t_0);
      	elseif (t_2 <= 0.0)
      		tmp = t_3;
      	elseif (t_2 <= Inf)
      		tmp = Float64(t_0 * cos(Float64(Float64(K / Float64(2.0 / m)) - M)));
      	else
      		tmp = t_3;
      	end
      	return tmp
      end
      
      NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
      code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[(t$95$1 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Exp[N[(t$95$1 - N[(M * N[(M * N[(N[(n + N[(-0.25 * N[(N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] + m), $MachinePrecision]), $MachinePrecision] / (-M)), $MachinePrecision] + M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]}, If[LessEqual[t$95$2, -0.2], N[(N[Cos[N[(N[(K / N[(N[(m / N[(n * n), $MachinePrecision]), $MachinePrecision] * -2.0 + N[(2.0 / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[t$95$2, 0.0], t$95$3, If[LessEqual[t$95$2, Infinity], N[(t$95$0 * N[Cos[N[(N[(K / N[(2.0 / m), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]]
      
      \begin{array}{l}
      [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
      \\
      \begin{array}{l}
      t_0 := e^{-\ell}\\
      t_1 := \left|m - n\right| - \ell\\
      t_2 := e^{t\_1 - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
      t_3 := e^{t\_1 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\
      \mathbf{if}\;t\_2 \leq -0.2:\\
      \;\;\;\;\cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \frac{2}{n}\right)} - M\right) \cdot t\_0\\
      
      \mathbf{elif}\;t\_2 \leq 0:\\
      \;\;\;\;t\_3\\
      
      \mathbf{elif}\;t\_2 \leq \infty:\\
      \;\;\;\;t\_0 \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_3\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 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.20000000000000001

        1. Initial program 39.0%

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

          \[\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.f6439.0

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \cos \left(\frac{K}{\color{blue}{\frac{2}{n + m}}} - M\right) \cdot e^{-\ell} \]
          11. lift-+.f64N/A

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

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

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

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

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

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

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

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

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

            \[\leadsto \cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{\color{blue}{n \cdot n}}, -2, 2 \cdot \frac{1}{n}\right)} - M\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
          6. associate-*r/N/A

            \[\leadsto \cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \color{blue}{\frac{2 \cdot 1}{n}}\right)} - M\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
          7. metadata-evalN/A

            \[\leadsto \cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \frac{\color{blue}{2}}{n}\right)} - M\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
          8. lower-/.f6440.9

            \[\leadsto \cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \color{blue}{\frac{2}{n}}\right)} - M\right) \cdot e^{-\ell} \]
        10. Applied rewrites40.9%

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

        if -0.20000000000000001 < (*.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.0 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 77.7%

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
        8. Applied rewrites100.0%

          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
        9. Taylor expanded in M around 0

          \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
        10. Step-by-step derivation
          1. Applied rewrites100.0%

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

          if -0.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)))))) < +inf.0

          1. Initial program 78.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 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.f6478.2

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \cos \left(\frac{K}{\color{blue}{\frac{2}{n + m}}} - M\right) \cdot e^{-\ell} \]
            11. lift-+.f64N/A

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

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

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

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

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

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

            \[\leadsto \cos \left(\frac{K}{\color{blue}{\frac{2}{m}}} - M\right) \cdot e^{-\ell} \]
        11. Recombined 3 regimes into one program.
        12. Final simplification94.8%

          \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq -0.2:\\ \;\;\;\;\cos \left(\frac{K}{\mathsf{fma}\left(\frac{m}{n \cdot n}, -2, \frac{2}{n}\right)} - M\right) \cdot e^{-\ell}\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq 0:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq \infty:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \end{array} \]
        13. Add Preprocessing

        Alternative 3: 96.8% accurate, 0.3× speedup?

        \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ t_2 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ t_3 := e^{-\ell}\\ \mathbf{if}\;t\_2 \leq -0.2:\\ \;\;\;\;t\_3 \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;t\_2 \leq 0:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;t\_3 \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
        NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
        (FPCore (K m n M l)
         :precision binary64
         (let* ((t_0 (- (fabs (- m n)) l))
                (t_1
                 (*
                  (exp
                   (-
                    t_0
                    (*
                     M
                     (fma
                      M
                      (/ (+ n (fma -0.25 (/ (* (+ m n) (+ m n)) M) m)) (- M))
                      M))))
                  1.0))
                (t_2
                 (*
                  (exp (- t_0 (pow (- (/ (+ m n) 2.0) M) 2.0)))
                  (cos (- (/ (* K (+ m n)) 2.0) M))))
                (t_3 (exp (- l))))
           (if (<= t_2 -0.2)
             (* t_3 (fma (* M M) -0.5 1.0))
             (if (<= t_2 0.0)
               t_1
               (if (<= t_2 INFINITY) (* t_3 (cos (- (/ K (/ 2.0 m)) M))) t_1)))))
        assert(K < m && m < n && n < M && M < l);
        double code(double K, double m, double n, double M, double l) {
        	double t_0 = fabs((m - n)) - l;
        	double t_1 = exp((t_0 - (M * fma(M, ((n + fma(-0.25, (((m + n) * (m + n)) / M), m)) / -M), M)))) * 1.0;
        	double t_2 = exp((t_0 - pow((((m + n) / 2.0) - M), 2.0))) * cos((((K * (m + n)) / 2.0) - M));
        	double t_3 = exp(-l);
        	double tmp;
        	if (t_2 <= -0.2) {
        		tmp = t_3 * fma((M * M), -0.5, 1.0);
        	} else if (t_2 <= 0.0) {
        		tmp = t_1;
        	} else if (t_2 <= ((double) INFINITY)) {
        		tmp = t_3 * cos(((K / (2.0 / m)) - M));
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        K, m, n, M, l = sort([K, m, n, M, l])
        function code(K, m, n, M, l)
        	t_0 = Float64(abs(Float64(m - n)) - l)
        	t_1 = Float64(exp(Float64(t_0 - Float64(M * fma(M, Float64(Float64(n + fma(-0.25, Float64(Float64(Float64(m + n) * Float64(m + n)) / M), m)) / Float64(-M)), M)))) * 1.0)
        	t_2 = Float64(exp(Float64(t_0 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))) * cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)))
        	t_3 = exp(Float64(-l))
        	tmp = 0.0
        	if (t_2 <= -0.2)
        		tmp = Float64(t_3 * fma(Float64(M * M), -0.5, 1.0));
        	elseif (t_2 <= 0.0)
        		tmp = t_1;
        	elseif (t_2 <= Inf)
        		tmp = Float64(t_3 * cos(Float64(Float64(K / Float64(2.0 / m)) - M)));
        	else
        		tmp = t_1;
        	end
        	return tmp
        end
        
        NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
        code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[N[(t$95$0 - N[(M * N[(M * N[(N[(n + N[(-0.25 * N[(N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] + m), $MachinePrecision]), $MachinePrecision] / (-M)), $MachinePrecision] + M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[(t$95$0 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Exp[(-l)], $MachinePrecision]}, If[LessEqual[t$95$2, -0.2], N[(t$95$3 * N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0], t$95$1, If[LessEqual[t$95$2, Infinity], N[(t$95$3 * N[Cos[N[(N[(K / N[(2.0 / m), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
        
        \begin{array}{l}
        [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
        \\
        \begin{array}{l}
        t_0 := \left|m - n\right| - \ell\\
        t_1 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\
        t_2 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
        t_3 := e^{-\ell}\\
        \mathbf{if}\;t\_2 \leq -0.2:\\
        \;\;\;\;t\_3 \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
        
        \mathbf{elif}\;t\_2 \leq 0:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;t\_2 \leq \infty:\\
        \;\;\;\;t\_3 \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 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.20000000000000001

          1. Initial program 39.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.f6469.8

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

            \[\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.f6469.8

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

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

            \[\leadsto \left(1 + \color{blue}{\frac{-1}{2} \cdot {M}^{2}}\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
          10. Step-by-step derivation
            1. Applied rewrites69.8%

              \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]

            if -0.20000000000000001 < (*.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.0 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 77.7%

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
            8. Applied rewrites100.0%

              \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
            9. Taylor expanded in M around 0

              \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
            10. Step-by-step derivation
              1. Applied rewrites100.0%

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

              if -0.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)))))) < +inf.0

              1. Initial program 78.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 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.f6478.2

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \cos \left(\frac{K}{\color{blue}{\frac{2}{n + m}}} - M\right) \cdot e^{-\ell} \]
                11. lift-+.f64N/A

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

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

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

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

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

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

                \[\leadsto \cos \left(\frac{K}{\color{blue}{\frac{2}{m}}} - M\right) \cdot e^{-\ell} \]
            11. Recombined 3 regimes into one program.
            12. Final simplification96.1%

              \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq -0.2:\\ \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq 0:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq \infty:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \end{array} \]
            13. Add Preprocessing

            Alternative 4: 96.6% accurate, 0.3× speedup?

            \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ t_2 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ t_3 := e^{-\ell}\\ \mathbf{if}\;t\_2 \leq -0.2:\\ \;\;\;\;t\_3 \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;t\_2 \leq 0:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;\cos M \cdot t\_3\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
            NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
            (FPCore (K m n M l)
             :precision binary64
             (let* ((t_0 (- (fabs (- m n)) l))
                    (t_1
                     (*
                      (exp
                       (-
                        t_0
                        (*
                         M
                         (fma
                          M
                          (/ (+ n (fma -0.25 (/ (* (+ m n) (+ m n)) M) m)) (- M))
                          M))))
                      1.0))
                    (t_2
                     (*
                      (exp (- t_0 (pow (- (/ (+ m n) 2.0) M) 2.0)))
                      (cos (- (/ (* K (+ m n)) 2.0) M))))
                    (t_3 (exp (- l))))
               (if (<= t_2 -0.2)
                 (* t_3 (fma (* M M) -0.5 1.0))
                 (if (<= t_2 0.0) t_1 (if (<= t_2 INFINITY) (* (cos M) t_3) t_1)))))
            assert(K < m && m < n && n < M && M < l);
            double code(double K, double m, double n, double M, double l) {
            	double t_0 = fabs((m - n)) - l;
            	double t_1 = exp((t_0 - (M * fma(M, ((n + fma(-0.25, (((m + n) * (m + n)) / M), m)) / -M), M)))) * 1.0;
            	double t_2 = exp((t_0 - pow((((m + n) / 2.0) - M), 2.0))) * cos((((K * (m + n)) / 2.0) - M));
            	double t_3 = exp(-l);
            	double tmp;
            	if (t_2 <= -0.2) {
            		tmp = t_3 * fma((M * M), -0.5, 1.0);
            	} else if (t_2 <= 0.0) {
            		tmp = t_1;
            	} else if (t_2 <= ((double) INFINITY)) {
            		tmp = cos(M) * t_3;
            	} else {
            		tmp = t_1;
            	}
            	return tmp;
            }
            
            K, m, n, M, l = sort([K, m, n, M, l])
            function code(K, m, n, M, l)
            	t_0 = Float64(abs(Float64(m - n)) - l)
            	t_1 = Float64(exp(Float64(t_0 - Float64(M * fma(M, Float64(Float64(n + fma(-0.25, Float64(Float64(Float64(m + n) * Float64(m + n)) / M), m)) / Float64(-M)), M)))) * 1.0)
            	t_2 = Float64(exp(Float64(t_0 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))) * cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)))
            	t_3 = exp(Float64(-l))
            	tmp = 0.0
            	if (t_2 <= -0.2)
            		tmp = Float64(t_3 * fma(Float64(M * M), -0.5, 1.0));
            	elseif (t_2 <= 0.0)
            		tmp = t_1;
            	elseif (t_2 <= Inf)
            		tmp = Float64(cos(M) * t_3);
            	else
            		tmp = t_1;
            	end
            	return tmp
            end
            
            NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
            code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[N[(t$95$0 - N[(M * N[(M * N[(N[(n + N[(-0.25 * N[(N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] + m), $MachinePrecision]), $MachinePrecision] / (-M)), $MachinePrecision] + M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[(t$95$0 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Exp[(-l)], $MachinePrecision]}, If[LessEqual[t$95$2, -0.2], N[(t$95$3 * N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0], t$95$1, If[LessEqual[t$95$2, Infinity], N[(N[Cos[M], $MachinePrecision] * t$95$3), $MachinePrecision], t$95$1]]]]]]]
            
            \begin{array}{l}
            [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
            \\
            \begin{array}{l}
            t_0 := \left|m - n\right| - \ell\\
            t_1 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\
            t_2 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
            t_3 := e^{-\ell}\\
            \mathbf{if}\;t\_2 \leq -0.2:\\
            \;\;\;\;t\_3 \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
            
            \mathbf{elif}\;t\_2 \leq 0:\\
            \;\;\;\;t\_1\\
            
            \mathbf{elif}\;t\_2 \leq \infty:\\
            \;\;\;\;\cos M \cdot t\_3\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_1\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 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.20000000000000001

              1. Initial program 39.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.f6469.8

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

                \[\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.f6469.8

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

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

                \[\leadsto \left(1 + \color{blue}{\frac{-1}{2} \cdot {M}^{2}}\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
              10. Step-by-step derivation
                1. Applied rewrites69.8%

                  \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]

                if -0.20000000000000001 < (*.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.0 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 77.7%

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                8. Applied rewrites100.0%

                  \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                9. Taylor expanded in M around 0

                  \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                10. Step-by-step derivation
                  1. Applied rewrites100.0%

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

                  if -0.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)))))) < +inf.0

                  1. Initial program 78.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.f6481.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 rewrites81.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.f6481.1

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

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq -0.2:\\ \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq 0:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq \infty:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \end{array} \]
                13. Add Preprocessing

                Alternative 5: 96.2% accurate, 0.3× speedup?

                \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ t_2 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ t_3 := e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{if}\;t\_2 \leq -0.5:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq 0.8:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
                NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                (FPCore (K m n M l)
                 :precision binary64
                 (let* ((t_0 (- (fabs (- m n)) l))
                        (t_1
                         (*
                          (exp
                           (-
                            t_0
                            (*
                             M
                             (fma
                              M
                              (/ (+ n (fma -0.25 (/ (* (+ m n) (+ m n)) M) m)) (- M))
                              M))))
                          1.0))
                        (t_2
                         (*
                          (exp (- t_0 (pow (- (/ (+ m n) 2.0) M) 2.0)))
                          (cos (- (/ (* K (+ m n)) 2.0) M))))
                        (t_3 (* (exp (- l)) (fma (* M M) -0.5 1.0))))
                   (if (<= t_2 -0.5)
                     t_3
                     (if (<= t_2 0.8) t_1 (if (<= t_2 INFINITY) t_3 t_1)))))
                assert(K < m && m < n && n < M && M < l);
                double code(double K, double m, double n, double M, double l) {
                	double t_0 = fabs((m - n)) - l;
                	double t_1 = exp((t_0 - (M * fma(M, ((n + fma(-0.25, (((m + n) * (m + n)) / M), m)) / -M), M)))) * 1.0;
                	double t_2 = exp((t_0 - pow((((m + n) / 2.0) - M), 2.0))) * cos((((K * (m + n)) / 2.0) - M));
                	double t_3 = exp(-l) * fma((M * M), -0.5, 1.0);
                	double tmp;
                	if (t_2 <= -0.5) {
                		tmp = t_3;
                	} else if (t_2 <= 0.8) {
                		tmp = t_1;
                	} else if (t_2 <= ((double) INFINITY)) {
                		tmp = t_3;
                	} else {
                		tmp = t_1;
                	}
                	return tmp;
                }
                
                K, m, n, M, l = sort([K, m, n, M, l])
                function code(K, m, n, M, l)
                	t_0 = Float64(abs(Float64(m - n)) - l)
                	t_1 = Float64(exp(Float64(t_0 - Float64(M * fma(M, Float64(Float64(n + fma(-0.25, Float64(Float64(Float64(m + n) * Float64(m + n)) / M), m)) / Float64(-M)), M)))) * 1.0)
                	t_2 = Float64(exp(Float64(t_0 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))) * cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)))
                	t_3 = Float64(exp(Float64(-l)) * fma(Float64(M * M), -0.5, 1.0))
                	tmp = 0.0
                	if (t_2 <= -0.5)
                		tmp = t_3;
                	elseif (t_2 <= 0.8)
                		tmp = t_1;
                	elseif (t_2 <= Inf)
                		tmp = t_3;
                	else
                		tmp = t_1;
                	end
                	return tmp
                end
                
                NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[N[(t$95$0 - N[(M * N[(M * N[(N[(n + N[(-0.25 * N[(N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] + m), $MachinePrecision]), $MachinePrecision] / (-M)), $MachinePrecision] + M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[(t$95$0 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Exp[(-l)], $MachinePrecision] * N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -0.5], t$95$3, If[LessEqual[t$95$2, 0.8], t$95$1, If[LessEqual[t$95$2, Infinity], t$95$3, t$95$1]]]]]]]
                
                \begin{array}{l}
                [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
                \\
                \begin{array}{l}
                t_0 := \left|m - n\right| - \ell\\
                t_1 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\
                t_2 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
                t_3 := e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
                \mathbf{if}\;t\_2 \leq -0.5:\\
                \;\;\;\;t\_3\\
                
                \mathbf{elif}\;t\_2 \leq 0.8:\\
                \;\;\;\;t\_1\\
                
                \mathbf{elif}\;t\_2 \leq \infty:\\
                \;\;\;\;t\_3\\
                
                \mathbf{else}:\\
                \;\;\;\;t\_1\\
                
                
                \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.5 or 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 71.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.f6481.2

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

                    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
                  6. Taylor expanded in 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.f6481.2

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

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

                    \[\leadsto \left(1 + \color{blue}{\frac{-1}{2} \cdot {M}^{2}}\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                  10. Step-by-step derivation
                    1. Applied rewrites81.2%

                      \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]

                    if -0.5 < (*.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 77.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                    9. Taylor expanded in M around 0

                      \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                    10. Step-by-step derivation
                      1. Applied rewrites99.2%

                        \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                    11. Recombined 2 regimes into one program.
                    12. Final simplification96.2%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq -0.5:\\ \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq 0.8:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq \infty:\\ \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \end{array} \]
                    13. Add Preprocessing

                    Alternative 6: 96.3% accurate, 0.4× speedup?

                    \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\ t_2 := t\_1 \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\ t_3 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)}\\ \mathbf{if}\;t\_2 \leq 0.9705712466018273:\\ \;\;\;\;\cos M \cdot t\_3\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;t\_1 \cdot \mathsf{fma}\left(0.5, K \cdot \left(M \cdot \left(m + n\right)\right), 1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_3 \cdot 1\\ \end{array} \end{array} \]
                    NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                    (FPCore (K m n M l)
                     :precision binary64
                     (let* ((t_0 (- (fabs (- m n)) l))
                            (t_1 (exp (- t_0 (pow (- (/ (+ m n) 2.0) M) 2.0))))
                            (t_2 (* t_1 (cos (- (/ (* K (+ m n)) 2.0) M))))
                            (t_3
                             (exp
                              (-
                               t_0
                               (*
                                M
                                (fma
                                 M
                                 (/ (+ n (fma -0.25 (/ (* (+ m n) (+ m n)) M) m)) (- M))
                                 M))))))
                       (if (<= t_2 0.9705712466018273)
                         (* (cos M) t_3)
                         (if (<= t_2 INFINITY)
                           (* t_1 (fma 0.5 (* K (* M (+ m n))) 1.0))
                           (* t_3 1.0)))))
                    assert(K < m && m < n && n < M && M < l);
                    double code(double K, double m, double n, double M, double l) {
                    	double t_0 = fabs((m - n)) - l;
                    	double t_1 = exp((t_0 - pow((((m + n) / 2.0) - M), 2.0)));
                    	double t_2 = t_1 * cos((((K * (m + n)) / 2.0) - M));
                    	double t_3 = exp((t_0 - (M * fma(M, ((n + fma(-0.25, (((m + n) * (m + n)) / M), m)) / -M), M))));
                    	double tmp;
                    	if (t_2 <= 0.9705712466018273) {
                    		tmp = cos(M) * t_3;
                    	} else if (t_2 <= ((double) INFINITY)) {
                    		tmp = t_1 * fma(0.5, (K * (M * (m + n))), 1.0);
                    	} else {
                    		tmp = t_3 * 1.0;
                    	}
                    	return tmp;
                    }
                    
                    K, m, n, M, l = sort([K, m, n, M, l])
                    function code(K, m, n, M, l)
                    	t_0 = Float64(abs(Float64(m - n)) - l)
                    	t_1 = exp(Float64(t_0 - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))
                    	t_2 = Float64(t_1 * cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)))
                    	t_3 = exp(Float64(t_0 - Float64(M * fma(M, Float64(Float64(n + fma(-0.25, Float64(Float64(Float64(m + n) * Float64(m + n)) / M), m)) / Float64(-M)), M))))
                    	tmp = 0.0
                    	if (t_2 <= 0.9705712466018273)
                    		tmp = Float64(cos(M) * t_3);
                    	elseif (t_2 <= Inf)
                    		tmp = Float64(t_1 * fma(0.5, Float64(K * Float64(M * Float64(m + n))), 1.0));
                    	else
                    		tmp = Float64(t_3 * 1.0);
                    	end
                    	return tmp
                    end
                    
                    NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                    code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(t$95$0 - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Exp[N[(t$95$0 - N[(M * N[(M * N[(N[(n + N[(-0.25 * N[(N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] + m), $MachinePrecision]), $MachinePrecision] / (-M)), $MachinePrecision] + M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$2, 0.9705712466018273], N[(N[Cos[M], $MachinePrecision] * t$95$3), $MachinePrecision], If[LessEqual[t$95$2, Infinity], N[(t$95$1 * N[(0.5 * N[(K * N[(M * N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(t$95$3 * 1.0), $MachinePrecision]]]]]]]
                    
                    \begin{array}{l}
                    [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
                    \\
                    \begin{array}{l}
                    t_0 := \left|m - n\right| - \ell\\
                    t_1 := e^{t\_0 - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
                    t_2 := t\_1 \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\\
                    t_3 := e^{t\_0 - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)}\\
                    \mathbf{if}\;t\_2 \leq 0.9705712466018273:\\
                    \;\;\;\;\cos M \cdot t\_3\\
                    
                    \mathbf{elif}\;t\_2 \leq \infty:\\
                    \;\;\;\;t\_1 \cdot \mathsf{fma}\left(0.5, K \cdot \left(M \cdot \left(m + n\right)\right), 1\right)\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;t\_3 \cdot 1\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 3 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.97057124660182725

                      1. Initial program 93.8%

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

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

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

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

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

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

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

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

                          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\mathsf{neg}\left(M \cdot \color{blue}{\mathsf{fma}\left(M, -1 \cdot \frac{m + \left(n + \frac{-1}{4} \cdot \frac{{\left(m + n\right)}^{2}}{M}\right)}{M}, M\right)}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                      5. Applied rewrites93.8%

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

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

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

                          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                      8. Applied rewrites95.1%

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

                      if 0.97057124660182725 < (*.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.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}{\left(\cos \left(\mathsf{neg}\left(M\right)\right) + \frac{-1}{2} \cdot \left(K \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\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. +-commutativeN/A

                          \[\leadsto \color{blue}{\left(\frac{-1}{2} \cdot \left(K \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right) + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
                        2. associate-*r*N/A

                          \[\leadsto \left(\color{blue}{\left(\frac{-1}{2} \cdot K\right) \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)} + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
                        3. *-commutativeN/A

                          \[\leadsto \left(\color{blue}{\left(K \cdot \frac{-1}{2}\right)} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right) + \cos \left(\mathsf{neg}\left(M\right)\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. associate-*l*N/A

                          \[\leadsto \left(\color{blue}{K \cdot \left(\frac{-1}{2} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right)} + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
                        5. metadata-evalN/A

                          \[\leadsto \left(K \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right) + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
                        6. distribute-lft-neg-inN/A

                          \[\leadsto \left(K \cdot \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right)\right)} + \cos \left(\mathsf{neg}\left(M\right)\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)} \]
                        7. lower-fma.f64N/A

                          \[\leadsto \color{blue}{\mathsf{fma}\left(K, \mathsf{neg}\left(\frac{1}{2} \cdot \left(\sin \left(\mathsf{neg}\left(M\right)\right) \cdot \left(m + n\right)\right)\right), \cos \left(\mathsf{neg}\left(M\right)\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)} \]
                      5. Applied rewrites96.6%

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

                        \[\leadsto \left(1 + \color{blue}{\frac{1}{2} \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\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)} \]
                      7. Step-by-step derivation
                        1. Applied rewrites96.6%

                          \[\leadsto \mathsf{fma}\left(0.5, \color{blue}{\left(M \cdot \left(n + m\right)\right) \cdot K}, 1\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\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 M around -inf

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                        8. Applied rewrites100.0%

                          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                        9. Taylor expanded in M around 0

                          \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                        10. Step-by-step derivation
                          1. Applied rewrites100.0%

                            \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                        11. Recombined 3 regimes into one program.
                        12. Final simplification96.1%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq 0.9705712466018273:\\ \;\;\;\;\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)}\\ \mathbf{elif}\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \leq \infty:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \mathsf{fma}\left(0.5, K \cdot \left(M \cdot \left(m + n\right)\right), 1\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(m + n\right) \cdot \left(m + n\right)}{M}, m\right)}{-M}, M\right)} \cdot 1\\ \end{array} \]
                        13. Add Preprocessing

                        Alternative 7: 96.8% accurate, 1.1× speedup?

                        \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \end{array} \]
                        NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                        (FPCore (K m n M l)
                         :precision binary64
                         (* (cos M) (exp (- (- (fabs (- m n)) l) (pow (- (/ (+ m n) 2.0) M) 2.0)))))
                        assert(K < m && m < n && n < M && M < l);
                        double code(double K, double m, double n, double M, double l) {
                        	return cos(M) * exp(((fabs((m - n)) - l) - pow((((m + n) / 2.0) - M), 2.0)));
                        }
                        
                        NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                        real(8) function code(k, m, n, m_1, l)
                            real(8), intent (in) :: k
                            real(8), intent (in) :: m
                            real(8), intent (in) :: n
                            real(8), intent (in) :: m_1
                            real(8), intent (in) :: l
                            code = cos(m_1) * exp(((abs((m - n)) - l) - ((((m + n) / 2.0d0) - m_1) ** 2.0d0)))
                        end function
                        
                        assert K < m && m < n && n < M && M < l;
                        public static double code(double K, double m, double n, double M, double l) {
                        	return Math.cos(M) * Math.exp(((Math.abs((m - n)) - l) - Math.pow((((m + n) / 2.0) - M), 2.0)));
                        }
                        
                        [K, m, n, M, l] = sort([K, m, n, M, l])
                        def code(K, m, n, M, l):
                        	return math.cos(M) * math.exp(((math.fabs((m - n)) - l) - math.pow((((m + n) / 2.0) - M), 2.0)))
                        
                        K, m, n, M, l = sort([K, m, n, M, l])
                        function code(K, m, n, M, l)
                        	return Float64(cos(M) * exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))))
                        end
                        
                        K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
                        function tmp = code(K, m, n, M, l)
                        	tmp = cos(M) * exp(((abs((m - n)) - l) - ((((m + n) / 2.0) - M) ^ 2.0)));
                        end
                        
                        NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                        code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
                        
                        \begin{array}{l}
                        [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
                        \\
                        \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
                        \end{array}
                        
                        Derivation
                        1. Initial program 76.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.f6496.2

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

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

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

                        Alternative 8: 94.5% accurate, 2.1× speedup?

                        \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -50000000000000:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{\frac{-0.25 \cdot \left(n \cdot n\right)}{M}}{-M}, M\right)}\\ \end{array} \end{array} \]
                        NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                        (FPCore (K m n M l)
                         :precision binary64
                         (if (<= m -50000000000000.0)
                           (* 1.0 (exp (* -0.25 (* m m))))
                           (*
                            1.0
                            (exp
                             (-
                              (- (fabs (- m n)) l)
                              (* M (fma M (/ (/ (* -0.25 (* n n)) M) (- M)) M)))))))
                        assert(K < m && m < n && n < M && M < l);
                        double code(double K, double m, double n, double M, double l) {
                        	double tmp;
                        	if (m <= -50000000000000.0) {
                        		tmp = 1.0 * exp((-0.25 * (m * m)));
                        	} else {
                        		tmp = 1.0 * exp(((fabs((m - n)) - l) - (M * fma(M, (((-0.25 * (n * n)) / M) / -M), M))));
                        	}
                        	return tmp;
                        }
                        
                        K, m, n, M, l = sort([K, m, n, M, l])
                        function code(K, m, n, M, l)
                        	tmp = 0.0
                        	if (m <= -50000000000000.0)
                        		tmp = Float64(1.0 * exp(Float64(-0.25 * Float64(m * m))));
                        	else
                        		tmp = Float64(1.0 * exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(M * fma(M, Float64(Float64(Float64(-0.25 * Float64(n * n)) / M) / Float64(-M)), M)))));
                        	end
                        	return tmp
                        end
                        
                        NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                        code[K_, m_, n_, M_, l_] := If[LessEqual[m, -50000000000000.0], N[(1.0 * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 * N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(M * N[(M * N[(N[(N[(-0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision] / M), $MachinePrecision] / (-M)), $MachinePrecision] + M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
                        
                        \begin{array}{l}
                        [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;m \leq -50000000000000:\\
                        \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;1 \cdot e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{\frac{-0.25 \cdot \left(n \cdot n\right)}{M}}{-M}, M\right)}\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if m < -5e13

                          1. Initial program 65.6%

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

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

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

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

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

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

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

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

                              \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\mathsf{neg}\left(M \cdot \color{blue}{\mathsf{fma}\left(M, -1 \cdot \frac{m + \left(n + \frac{-1}{4} \cdot \frac{{\left(m + n\right)}^{2}}{M}\right)}{M}, M\right)}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                          5. Applied rewrites65.6%

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

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

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

                              \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                          8. Applied rewrites100.0%

                            \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                          9. Taylor expanded in M around 0

                            \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                          10. Step-by-step derivation
                            1. Applied rewrites98.4%

                              \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                            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. lower-*.f64N/A

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

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

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

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

                            if -5e13 < m

                            1. Initial program 79.6%

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

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

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

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

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

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

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

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

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

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

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

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

                                \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                            8. Applied rewrites89.7%

                              \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                            9. Taylor expanded in M around 0

                              \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                            10. Step-by-step derivation
                              1. Applied rewrites87.6%

                                \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                              2. Taylor expanded in n around inf

                                \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{\frac{-1}{4} \cdot \frac{{n}^{2}}{M}}{\mathsf{neg}\left(\color{blue}{M}\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                              3. Step-by-step derivation
                                1. Applied rewrites82.0%

                                  \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{\frac{-0.25 \cdot \left(n \cdot n\right)}{M}}{-\color{blue}{M}}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                              4. Recombined 2 regimes into one program.
                              5. Final simplification86.1%

                                \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -50000000000000:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot e^{\left(\left|m - n\right| - \ell\right) - M \cdot \mathsf{fma}\left(M, \frac{\frac{-0.25 \cdot \left(n \cdot n\right)}{M}}{-M}, M\right)}\\ \end{array} \]
                              6. Add Preprocessing

                              Alternative 9: 80.3% accurate, 2.7× speedup?

                              \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.65 \cdot 10^{-37}:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{elif}\;m \leq -1.22 \cdot 10^{-296}:\\ \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \end{array} \]
                              NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                              (FPCore (K m n M l)
                               :precision binary64
                               (if (<= m -54.0)
                                 (* 1.0 (exp (* -0.25 (* m m))))
                                 (if (<= m -1.65e-37)
                                   (* 1.0 (exp (- l)))
                                   (if (<= m -1.22e-296)
                                     (* 1.0 (exp (* M (- M))))
                                     (* 1.0 (exp (* -0.25 (* n n))))))))
                              assert(K < m && m < n && n < M && M < l);
                              double code(double K, double m, double n, double M, double l) {
                              	double tmp;
                              	if (m <= -54.0) {
                              		tmp = 1.0 * exp((-0.25 * (m * m)));
                              	} else if (m <= -1.65e-37) {
                              		tmp = 1.0 * exp(-l);
                              	} else if (m <= -1.22e-296) {
                              		tmp = 1.0 * exp((M * -M));
                              	} else {
                              		tmp = 1.0 * exp((-0.25 * (n * n)));
                              	}
                              	return tmp;
                              }
                              
                              NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                              real(8) function code(k, m, n, m_1, l)
                                  real(8), intent (in) :: k
                                  real(8), intent (in) :: m
                                  real(8), intent (in) :: n
                                  real(8), intent (in) :: m_1
                                  real(8), intent (in) :: l
                                  real(8) :: tmp
                                  if (m <= (-54.0d0)) then
                                      tmp = 1.0d0 * exp(((-0.25d0) * (m * m)))
                                  else if (m <= (-1.65d-37)) then
                                      tmp = 1.0d0 * exp(-l)
                                  else if (m <= (-1.22d-296)) then
                                      tmp = 1.0d0 * exp((m_1 * -m_1))
                                  else
                                      tmp = 1.0d0 * exp(((-0.25d0) * (n * n)))
                                  end if
                                  code = tmp
                              end function
                              
                              assert K < m && m < n && n < M && M < l;
                              public static double code(double K, double m, double n, double M, double l) {
                              	double tmp;
                              	if (m <= -54.0) {
                              		tmp = 1.0 * Math.exp((-0.25 * (m * m)));
                              	} else if (m <= -1.65e-37) {
                              		tmp = 1.0 * Math.exp(-l);
                              	} else if (m <= -1.22e-296) {
                              		tmp = 1.0 * Math.exp((M * -M));
                              	} else {
                              		tmp = 1.0 * Math.exp((-0.25 * (n * n)));
                              	}
                              	return tmp;
                              }
                              
                              [K, m, n, M, l] = sort([K, m, n, M, l])
                              def code(K, m, n, M, l):
                              	tmp = 0
                              	if m <= -54.0:
                              		tmp = 1.0 * math.exp((-0.25 * (m * m)))
                              	elif m <= -1.65e-37:
                              		tmp = 1.0 * math.exp(-l)
                              	elif m <= -1.22e-296:
                              		tmp = 1.0 * math.exp((M * -M))
                              	else:
                              		tmp = 1.0 * math.exp((-0.25 * (n * n)))
                              	return tmp
                              
                              K, m, n, M, l = sort([K, m, n, M, l])
                              function code(K, m, n, M, l)
                              	tmp = 0.0
                              	if (m <= -54.0)
                              		tmp = Float64(1.0 * exp(Float64(-0.25 * Float64(m * m))));
                              	elseif (m <= -1.65e-37)
                              		tmp = Float64(1.0 * exp(Float64(-l)));
                              	elseif (m <= -1.22e-296)
                              		tmp = Float64(1.0 * exp(Float64(M * Float64(-M))));
                              	else
                              		tmp = Float64(1.0 * exp(Float64(-0.25 * Float64(n * n))));
                              	end
                              	return tmp
                              end
                              
                              K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
                              function tmp_2 = code(K, m, n, M, l)
                              	tmp = 0.0;
                              	if (m <= -54.0)
                              		tmp = 1.0 * exp((-0.25 * (m * m)));
                              	elseif (m <= -1.65e-37)
                              		tmp = 1.0 * exp(-l);
                              	elseif (m <= -1.22e-296)
                              		tmp = 1.0 * exp((M * -M));
                              	else
                              		tmp = 1.0 * exp((-0.25 * (n * n)));
                              	end
                              	tmp_2 = tmp;
                              end
                              
                              NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                              code[K_, m_, n_, M_, l_] := If[LessEqual[m, -54.0], N[(1.0 * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, -1.65e-37], N[(1.0 * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, -1.22e-296], N[(1.0 * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 * N[Exp[N[(-0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
                              
                              \begin{array}{l}
                              [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;m \leq -54:\\
                              \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\
                              
                              \mathbf{elif}\;m \leq -1.65 \cdot 10^{-37}:\\
                              \;\;\;\;1 \cdot e^{-\ell}\\
                              
                              \mathbf{elif}\;m \leq -1.22 \cdot 10^{-296}:\\
                              \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;1 \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\
                              
                              
                              \end{array}
                              \end{array}
                              
                              Derivation
                              1. Split input into 4 regimes
                              2. if m < -54

                                1. Initial program 66.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^{\left(\mathsf{neg}\left(\color{blue}{{M}^{2} \cdot \left(1 + -1 \cdot \frac{m + \left(n + \frac{-1}{4} \cdot \frac{{\left(m + n\right)}^{2}}{M}\right)}{M}\right)}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                4. Step-by-step derivation
                                  1. unpow2N/A

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

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

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

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

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

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

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

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

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

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

                                    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                8. Applied rewrites100.0%

                                  \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                9. Taylor expanded in M around 0

                                  \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                10. Step-by-step derivation
                                  1. Applied rewrites98.5%

                                    \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                  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. lower-*.f64N/A

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

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

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

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

                                  if -54 < m < -1.64999999999999991e-37

                                  1. Initial program 81.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.f6464.8

                                      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
                                  8. Applied rewrites64.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 rewrites64.8%

                                      \[\leadsto 1 \cdot e^{-\ell} \]

                                    if -1.64999999999999991e-37 < m < -1.22e-296

                                    1. Initial program 82.9%

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                    8. Applied rewrites85.1%

                                      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                    9. Taylor expanded in M around 0

                                      \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                    10. Step-by-step derivation
                                      1. Applied rewrites83.3%

                                        \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                      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. lower-neg.f64N/A

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

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

                                          \[\leadsto 1 \cdot e^{-\color{blue}{M \cdot M}} \]
                                      4. Applied rewrites56.0%

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

                                      if -1.22e-296 < m

                                      1. Initial program 77.8%

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

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

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

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

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

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

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

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

                                          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\mathsf{neg}\left(M \cdot \color{blue}{\mathsf{fma}\left(M, -1 \cdot \frac{m + \left(n + \frac{-1}{4} \cdot \frac{{\left(m + n\right)}^{2}}{M}\right)}{M}, M\right)}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                      5. Applied rewrites73.8%

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

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

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

                                          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                      8. Applied rewrites91.6%

                                        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                      9. Taylor expanded in M around 0

                                        \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                      10. Step-by-step derivation
                                        1. Applied rewrites89.2%

                                          \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                        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. lower-*.f64N/A

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

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

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

                                          \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot \left(n \cdot n\right)}} \]
                                      11. Recombined 4 regimes into one program.
                                      12. Final simplification65.5%

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.65 \cdot 10^{-37}:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{elif}\;m \leq -1.22 \cdot 10^{-296}:\\ \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]
                                      13. Add Preprocessing

                                      Alternative 10: 77.1% accurate, 2.7× speedup?

                                      \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := 1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{if}\;m \leq -54:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;m \leq -1.65 \cdot 10^{-37}:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{elif}\;m \leq 62000:\\ \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                                      NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                      (FPCore (K m n M l)
                                       :precision binary64
                                       (let* ((t_0 (* 1.0 (exp (* -0.25 (* m m))))))
                                         (if (<= m -54.0)
                                           t_0
                                           (if (<= m -1.65e-37)
                                             (* 1.0 (exp (- l)))
                                             (if (<= m 62000.0) (* 1.0 (exp (* M (- M)))) t_0)))))
                                      assert(K < m && m < n && n < M && M < l);
                                      double code(double K, double m, double n, double M, double l) {
                                      	double t_0 = 1.0 * exp((-0.25 * (m * m)));
                                      	double tmp;
                                      	if (m <= -54.0) {
                                      		tmp = t_0;
                                      	} else if (m <= -1.65e-37) {
                                      		tmp = 1.0 * exp(-l);
                                      	} else if (m <= 62000.0) {
                                      		tmp = 1.0 * exp((M * -M));
                                      	} else {
                                      		tmp = t_0;
                                      	}
                                      	return tmp;
                                      }
                                      
                                      NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                      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(((-0.25d0) * (m * m)))
                                          if (m <= (-54.0d0)) then
                                              tmp = t_0
                                          else if (m <= (-1.65d-37)) then
                                              tmp = 1.0d0 * exp(-l)
                                          else if (m <= 62000.0d0) then
                                              tmp = 1.0d0 * exp((m_1 * -m_1))
                                          else
                                              tmp = t_0
                                          end if
                                          code = tmp
                                      end function
                                      
                                      assert K < m && m < n && n < M && M < l;
                                      public static double code(double K, double m, double n, double M, double l) {
                                      	double t_0 = 1.0 * Math.exp((-0.25 * (m * m)));
                                      	double tmp;
                                      	if (m <= -54.0) {
                                      		tmp = t_0;
                                      	} else if (m <= -1.65e-37) {
                                      		tmp = 1.0 * Math.exp(-l);
                                      	} else if (m <= 62000.0) {
                                      		tmp = 1.0 * Math.exp((M * -M));
                                      	} else {
                                      		tmp = t_0;
                                      	}
                                      	return tmp;
                                      }
                                      
                                      [K, m, n, M, l] = sort([K, m, n, M, l])
                                      def code(K, m, n, M, l):
                                      	t_0 = 1.0 * math.exp((-0.25 * (m * m)))
                                      	tmp = 0
                                      	if m <= -54.0:
                                      		tmp = t_0
                                      	elif m <= -1.65e-37:
                                      		tmp = 1.0 * math.exp(-l)
                                      	elif m <= 62000.0:
                                      		tmp = 1.0 * math.exp((M * -M))
                                      	else:
                                      		tmp = t_0
                                      	return tmp
                                      
                                      K, m, n, M, l = sort([K, m, n, M, l])
                                      function code(K, m, n, M, l)
                                      	t_0 = Float64(1.0 * exp(Float64(-0.25 * Float64(m * m))))
                                      	tmp = 0.0
                                      	if (m <= -54.0)
                                      		tmp = t_0;
                                      	elseif (m <= -1.65e-37)
                                      		tmp = Float64(1.0 * exp(Float64(-l)));
                                      	elseif (m <= 62000.0)
                                      		tmp = Float64(1.0 * exp(Float64(M * Float64(-M))));
                                      	else
                                      		tmp = t_0;
                                      	end
                                      	return tmp
                                      end
                                      
                                      K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
                                      function tmp_2 = code(K, m, n, M, l)
                                      	t_0 = 1.0 * exp((-0.25 * (m * m)));
                                      	tmp = 0.0;
                                      	if (m <= -54.0)
                                      		tmp = t_0;
                                      	elseif (m <= -1.65e-37)
                                      		tmp = 1.0 * exp(-l);
                                      	elseif (m <= 62000.0)
                                      		tmp = 1.0 * exp((M * -M));
                                      	else
                                      		tmp = t_0;
                                      	end
                                      	tmp_2 = tmp;
                                      end
                                      
                                      NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                      code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(1.0 * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[m, -54.0], t$95$0, If[LessEqual[m, -1.65e-37], N[(1.0 * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 62000.0], N[(1.0 * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
                                      
                                      \begin{array}{l}
                                      [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
                                      \\
                                      \begin{array}{l}
                                      t_0 := 1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\
                                      \mathbf{if}\;m \leq -54:\\
                                      \;\;\;\;t\_0\\
                                      
                                      \mathbf{elif}\;m \leq -1.65 \cdot 10^{-37}:\\
                                      \;\;\;\;1 \cdot e^{-\ell}\\
                                      
                                      \mathbf{elif}\;m \leq 62000:\\
                                      \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;t\_0\\
                                      
                                      
                                      \end{array}
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 3 regimes
                                      2. if m < -54 or 62000 < m

                                        1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                        8. Applied rewrites98.4%

                                          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                        9. Taylor expanded in M around 0

                                          \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                        10. Step-by-step derivation
                                          1. Applied rewrites96.7%

                                            \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                          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. lower-*.f64N/A

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

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

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

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

                                          if -54 < m < -1.64999999999999991e-37

                                          1. Initial program 81.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.f6464.8

                                              \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
                                          8. Applied rewrites64.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 rewrites64.8%

                                              \[\leadsto 1 \cdot e^{-\ell} \]

                                            if -1.64999999999999991e-37 < m < 62000

                                            1. Initial program 78.0%

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

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

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

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

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

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

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

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

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

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

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

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

                                                \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                            8. Applied rewrites86.4%

                                              \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                            9. Taylor expanded in M around 0

                                              \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                            10. Step-by-step derivation
                                              1. Applied rewrites83.9%

                                                \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                              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. lower-neg.f64N/A

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

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

                                                  \[\leadsto 1 \cdot e^{-\color{blue}{M \cdot M}} \]
                                              4. Applied rewrites53.5%

                                                \[\leadsto 1 \cdot e^{\color{blue}{-M \cdot M}} \]
                                            11. Recombined 3 regimes into one program.
                                            12. Final simplification74.2%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.65 \cdot 10^{-37}:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{elif}\;m \leq 62000:\\ \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \end{array} \]
                                            13. Add Preprocessing

                                            Alternative 11: 69.4% accurate, 2.9× speedup?

                                            \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := 1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -51:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 2 \cdot 10^{-16}:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                                            NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                            (FPCore (K m n M l)
                                             :precision binary64
                                             (let* ((t_0 (* 1.0 (exp (* M (- M))))))
                                               (if (<= M -51.0) t_0 (if (<= M 2e-16) (* 1.0 (exp (- l))) t_0))))
                                            assert(K < m && m < n && n < M && M < l);
                                            double code(double K, double m, double n, double M, double l) {
                                            	double t_0 = 1.0 * exp((M * -M));
                                            	double tmp;
                                            	if (M <= -51.0) {
                                            		tmp = t_0;
                                            	} else if (M <= 2e-16) {
                                            		tmp = 1.0 * exp(-l);
                                            	} else {
                                            		tmp = t_0;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                            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 <= (-51.0d0)) then
                                                    tmp = t_0
                                                else if (m_1 <= 2d-16) then
                                                    tmp = 1.0d0 * exp(-l)
                                                else
                                                    tmp = t_0
                                                end if
                                                code = tmp
                                            end function
                                            
                                            assert K < m && m < n && n < M && M < l;
                                            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 <= -51.0) {
                                            		tmp = t_0;
                                            	} else if (M <= 2e-16) {
                                            		tmp = 1.0 * Math.exp(-l);
                                            	} else {
                                            		tmp = t_0;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            [K, m, n, M, l] = sort([K, m, n, M, l])
                                            def code(K, m, n, M, l):
                                            	t_0 = 1.0 * math.exp((M * -M))
                                            	tmp = 0
                                            	if M <= -51.0:
                                            		tmp = t_0
                                            	elif M <= 2e-16:
                                            		tmp = 1.0 * math.exp(-l)
                                            	else:
                                            		tmp = t_0
                                            	return tmp
                                            
                                            K, m, n, M, l = sort([K, m, n, M, l])
                                            function code(K, m, n, M, l)
                                            	t_0 = Float64(1.0 * exp(Float64(M * Float64(-M))))
                                            	tmp = 0.0
                                            	if (M <= -51.0)
                                            		tmp = t_0;
                                            	elseif (M <= 2e-16)
                                            		tmp = Float64(1.0 * exp(Float64(-l)));
                                            	else
                                            		tmp = t_0;
                                            	end
                                            	return tmp
                                            end
                                            
                                            K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
                                            function tmp_2 = code(K, m, n, M, l)
                                            	t_0 = 1.0 * exp((M * -M));
                                            	tmp = 0.0;
                                            	if (M <= -51.0)
                                            		tmp = t_0;
                                            	elseif (M <= 2e-16)
                                            		tmp = 1.0 * exp(-l);
                                            	else
                                            		tmp = t_0;
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                            code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(1.0 * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -51.0], t$95$0, If[LessEqual[M, 2e-16], N[(1.0 * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], t$95$0]]]
                                            
                                            \begin{array}{l}
                                            [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
                                            \\
                                            \begin{array}{l}
                                            t_0 := 1 \cdot e^{M \cdot \left(-M\right)}\\
                                            \mathbf{if}\;M \leq -51:\\
                                            \;\;\;\;t\_0\\
                                            
                                            \mathbf{elif}\;M \leq 2 \cdot 10^{-16}:\\
                                            \;\;\;\;1 \cdot e^{-\ell}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;t\_0\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if M < -51 or 2e-16 < M

                                              1. Initial program 83.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                              9. Taylor expanded in M around 0

                                                \[\leadsto 1 \cdot e^{\left(\mathsf{neg}\left(M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(\frac{-1}{4}, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{\mathsf{neg}\left(M\right)}, M\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                              10. Step-by-step derivation
                                                1. Applied rewrites95.1%

                                                  \[\leadsto 1 \cdot e^{\left(-M \cdot \mathsf{fma}\left(M, \frac{n + \mathsf{fma}\left(-0.25, \frac{\left(n + m\right) \cdot \left(n + m\right)}{M}, m\right)}{-M}, M\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
                                                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. lower-neg.f64N/A

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

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

                                                    \[\leadsto 1 \cdot e^{-\color{blue}{M \cdot M}} \]
                                                4. Applied rewrites93.6%

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

                                                if -51 < M < 2e-16

                                                1. Initial program 69.9%

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

                                                  \[\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.f6493.5

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

                                                  \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
                                                6. Taylor expanded in 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.f6443.3

                                                    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
                                                8. Applied rewrites43.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 rewrites43.3%

                                                    \[\leadsto 1 \cdot e^{-\ell} \]
                                                11. Recombined 2 regimes into one program.
                                                12. Final simplification67.3%

                                                  \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -51:\\ \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;M \leq 2 \cdot 10^{-16}:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot e^{M \cdot \left(-M\right)}\\ \end{array} \]
                                                13. Add Preprocessing

                                                Alternative 12: 34.4% accurate, 3.3× speedup?

                                                \[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ 1 \cdot e^{-\ell} \end{array} \]
                                                NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                                (FPCore (K m n M l) :precision binary64 (* 1.0 (exp (- l))))
                                                assert(K < m && m < n && n < M && M < l);
                                                double code(double K, double m, double n, double M, double l) {
                                                	return 1.0 * exp(-l);
                                                }
                                                
                                                NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                                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
                                                
                                                assert K < m && m < n && n < M && M < l;
                                                public static double code(double K, double m, double n, double M, double l) {
                                                	return 1.0 * Math.exp(-l);
                                                }
                                                
                                                [K, m, n, M, l] = sort([K, m, n, M, l])
                                                def code(K, m, n, M, l):
                                                	return 1.0 * math.exp(-l)
                                                
                                                K, m, n, M, l = sort([K, m, n, M, l])
                                                function code(K, m, n, M, l)
                                                	return Float64(1.0 * exp(Float64(-l)))
                                                end
                                                
                                                K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
                                                function tmp = code(K, m, n, M, l)
                                                	tmp = 1.0 * exp(-l);
                                                end
                                                
                                                NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
                                                code[K_, m_, n_, M_, l_] := N[(1.0 * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]
                                                
                                                \begin{array}{l}
                                                [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
                                                \\
                                                1 \cdot e^{-\ell}
                                                \end{array}
                                                
                                                Derivation
                                                1. Initial program 76.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.f6496.2

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

                                                  \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
                                                6. Taylor expanded in 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.4

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

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

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

                                                  Reproduce

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