Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.4% → 96.6%
Time: 9.9s
Alternatives: 11
Speedup: 1.5×

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 11 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.4% accurate, 1.0× speedup?

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

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

Alternative 1: 96.6% accurate, 1.1× speedup?

\[\begin{array}{l} \\ e^{\left|n - m\right| - \left({\left(\mathsf{fma}\left(0.5, n + m, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (* (exp (- (fabs (- n m)) (+ (pow (fma 0.5 (+ n m) (- M)) 2.0) l))) (cos M)))
double code(double K, double m, double n, double M, double l) {
	return exp((fabs((n - m)) - (pow(fma(0.5, (n + m), -M), 2.0) + l))) * cos(M);
}
function code(K, m, n, M, l)
	return Float64(exp(Float64(abs(Float64(n - m)) - Float64((fma(0.5, Float64(n + m), Float64(-M)) ^ 2.0) + l))) * cos(M))
end
code[K_, m_, n_, M_, l_] := N[(N[Exp[N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - N[(N[Power[N[(0.5 * N[(n + m), $MachinePrecision] + (-M)), $MachinePrecision], 2.0], $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[M], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
e^{\left|n - m\right| - \left({\left(\mathsf{fma}\left(0.5, n + m, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M
\end{array}
Derivation
  1. Initial program 77.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|m - n\right| - \left(\ell + {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}\right)}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

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

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

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

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

Alternative 2: 37.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_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|n - m\right|\right)}\\ \mathbf{if}\;t\_1 \leq 0.4 \lor \neg \left(t\_1 \leq \infty\right):\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, M \cdot M, -0.5\right), M \cdot M, 1\right) \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- l)))
        (t_1
         (*
          (cos (- (/ (* K (+ m n)) 2.0) M))
          (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- n m))))))))
   (if (or (<= t_1 0.4) (not (<= t_1 INFINITY)))
     (* (* (* M M) -0.5) t_0)
     (* (fma (fma 0.041666666666666664 (* M M) -0.5) (* M M) 1.0) t_0))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(-l);
	double t_1 = cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - fabs((n - m)))));
	double tmp;
	if ((t_1 <= 0.4) || !(t_1 <= ((double) INFINITY))) {
		tmp = ((M * M) * -0.5) * t_0;
	} else {
		tmp = fma(fma(0.041666666666666664, (M * M), -0.5), (M * M), 1.0) * t_0;
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = exp(Float64(-l))
	t_1 = 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(n - m))))))
	tmp = 0.0
	if ((t_1 <= 0.4) || !(t_1 <= Inf))
		tmp = Float64(Float64(Float64(M * M) * -0.5) * t_0);
	else
		tmp = Float64(fma(fma(0.041666666666666664, Float64(M * M), -0.5), Float64(M * M), 1.0) * t_0);
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = 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[(n - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 0.4], N[Not[LessEqual[t$95$1, Infinity]], $MachinePrecision]], N[(N[(N[(M * M), $MachinePrecision] * -0.5), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[(N[(0.041666666666666664 * N[(M * M), $MachinePrecision] + -0.5), $MachinePrecision] * N[(M * M), $MachinePrecision] + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_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|n - m\right|\right)}\\
\mathbf{if}\;t\_1 \leq 0.4 \lor \neg \left(t\_1 \leq \infty\right):\\
\;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t\_0\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, M \cdot M, -0.5\right), M \cdot M, 1\right) \cdot t\_0\\


\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.40000000000000002 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 75.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.f6427.2

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

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

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
    7. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. lower-cos.f6433.9

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

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

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

        \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]
      2. Taylor expanded in M around inf

        \[\leadsto \left(\frac{-1}{2} \cdot {M}^{\color{blue}{2}}\right) \cdot e^{-\ell} \]
      3. Step-by-step derivation
        1. Applied rewrites36.4%

          \[\leadsto \left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell} \]

        if 0.40000000000000002 < (*.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 92.3%

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

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

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

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

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

          \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
        7. Step-by-step derivation
          1. cos-negN/A

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, M \cdot M, -0.5\right), \color{blue}{M \cdot M}, 1\right) \cdot e^{-\ell} \]
        11. Recombined 2 regimes into one program.
        12. Final simplification43.1%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\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|n - m\right|\right)} \leq 0.4 \lor \neg \left(\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|n - m\right|\right)} \leq \infty\right):\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, M \cdot M, -0.5\right), M \cdot M, 1\right) \cdot e^{-\ell}\\ \end{array} \]
        13. Add Preprocessing

        Alternative 3: 37.0% accurate, 0.4× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_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|n - m\right|\right)}\\ \mathbf{if}\;t\_1 \leq 0.4 \lor \neg \left(t\_1 \leq \infty\right):\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(M \cdot M, -0.5, 1\right) \cdot t\_0\\ \end{array} \end{array} \]
        (FPCore (K m n M l)
         :precision binary64
         (let* ((t_0 (exp (- l)))
                (t_1
                 (*
                  (cos (- (/ (* K (+ m n)) 2.0) M))
                  (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- n m))))))))
           (if (or (<= t_1 0.4) (not (<= t_1 INFINITY)))
             (* (* (* M M) -0.5) t_0)
             (* (fma (* M M) -0.5 1.0) t_0))))
        double code(double K, double m, double n, double M, double l) {
        	double t_0 = exp(-l);
        	double t_1 = cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - fabs((n - m)))));
        	double tmp;
        	if ((t_1 <= 0.4) || !(t_1 <= ((double) INFINITY))) {
        		tmp = ((M * M) * -0.5) * t_0;
        	} else {
        		tmp = fma((M * M), -0.5, 1.0) * t_0;
        	}
        	return tmp;
        }
        
        function code(K, m, n, M, l)
        	t_0 = exp(Float64(-l))
        	t_1 = 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(n - m))))))
        	tmp = 0.0
        	if ((t_1 <= 0.4) || !(t_1 <= Inf))
        		tmp = Float64(Float64(Float64(M * M) * -0.5) * t_0);
        	else
        		tmp = Float64(fma(Float64(M * M), -0.5, 1.0) * t_0);
        	end
        	return tmp
        end
        
        code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = 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[(n - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 0.4], N[Not[LessEqual[t$95$1, Infinity]], $MachinePrecision]], N[(N[(N[(M * M), $MachinePrecision] * -0.5), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := e^{-\ell}\\
        t_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|n - m\right|\right)}\\
        \mathbf{if}\;t\_1 \leq 0.4 \lor \neg \left(t\_1 \leq \infty\right):\\
        \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t\_0\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(M \cdot M, -0.5, 1\right) \cdot t\_0\\
        
        
        \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.40000000000000002 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 75.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.f6427.2

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

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

            \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
          7. Step-by-step derivation
            1. cos-negN/A

              \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
            2. lower-cos.f6433.9

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

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

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

              \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]
            2. Taylor expanded in M around inf

              \[\leadsto \left(\frac{-1}{2} \cdot {M}^{\color{blue}{2}}\right) \cdot e^{-\ell} \]
            3. Step-by-step derivation
              1. Applied rewrites36.4%

                \[\leadsto \left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell} \]

              if 0.40000000000000002 < (*.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 92.3%

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

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

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

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

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

                \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
              7. Step-by-step derivation
                1. cos-negN/A

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]
              11. Recombined 2 regimes into one program.
              12. Final simplification41.9%

                \[\leadsto \begin{array}{l} \mathbf{if}\;\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|n - m\right|\right)} \leq 0.4 \lor \neg \left(\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|n - m\right|\right)} \leq \infty\right):\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(M \cdot M, -0.5, 1\right) \cdot e^{-\ell}\\ \end{array} \]
              13. Add Preprocessing

              Alternative 4: 90.2% accurate, 0.6× speedup?

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

                1. Initial program 94.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto e^{\frac{-1}{4} \cdot {m}^{2}} \cdot \cos M \]
                7. Step-by-step derivation
                  1. Applied rewrites65.0%

                    \[\leadsto e^{\left(m \cdot m\right) \cdot -0.25} \cdot \cos M \]
                8. Recombined 2 regimes into one program.
                9. Final simplification89.1%

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

                Alternative 5: 91.2% accurate, 1.4× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;M \leq -4.5 \cdot 10^{+23} \lor \neg \left(M \leq 1.7 \cdot 10^{-5}\right):\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \cos M\\ \mathbf{else}:\\ \;\;\;\;e^{\left|n - m\right| - \left({\left(\mathsf{fma}\left(0.5, n + m, -M\right)\right)}^{2} + \ell\right)} \cdot \mathsf{fma}\left(\left(M \cdot \left(n + m\right)\right) \cdot K, 0.5, 1\right)\\ \end{array} \end{array} \]
                (FPCore (K m n M l)
                 :precision binary64
                 (if (or (<= M -4.5e+23) (not (<= M 1.7e-5)))
                   (* (exp (* (- M) M)) (cos M))
                   (*
                    (exp (- (fabs (- n m)) (+ (pow (fma 0.5 (+ n m) (- M)) 2.0) l)))
                    (fma (* (* M (+ n m)) K) 0.5 1.0))))
                double code(double K, double m, double n, double M, double l) {
                	double tmp;
                	if ((M <= -4.5e+23) || !(M <= 1.7e-5)) {
                		tmp = exp((-M * M)) * cos(M);
                	} else {
                		tmp = exp((fabs((n - m)) - (pow(fma(0.5, (n + m), -M), 2.0) + l))) * fma(((M * (n + m)) * K), 0.5, 1.0);
                	}
                	return tmp;
                }
                
                function code(K, m, n, M, l)
                	tmp = 0.0
                	if ((M <= -4.5e+23) || !(M <= 1.7e-5))
                		tmp = Float64(exp(Float64(Float64(-M) * M)) * cos(M));
                	else
                		tmp = Float64(exp(Float64(abs(Float64(n - m)) - Float64((fma(0.5, Float64(n + m), Float64(-M)) ^ 2.0) + l))) * fma(Float64(Float64(M * Float64(n + m)) * K), 0.5, 1.0));
                	end
                	return tmp
                end
                
                code[K_, m_, n_, M_, l_] := If[Or[LessEqual[M, -4.5e+23], N[Not[LessEqual[M, 1.7e-5]], $MachinePrecision]], N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * N[Cos[M], $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - N[(N[Power[N[(0.5 * N[(n + m), $MachinePrecision] + (-M)), $MachinePrecision], 2.0], $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[(N[(M * N[(n + m), $MachinePrecision]), $MachinePrecision] * K), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;M \leq -4.5 \cdot 10^{+23} \lor \neg \left(M \leq 1.7 \cdot 10^{-5}\right):\\
                \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \cos M\\
                
                \mathbf{else}:\\
                \;\;\;\;e^{\left|n - m\right| - \left({\left(\mathsf{fma}\left(0.5, n + m, -M\right)\right)}^{2} + \ell\right)} \cdot \mathsf{fma}\left(\left(M \cdot \left(n + m\right)\right) \cdot K, 0.5, 1\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if M < -4.49999999999999979e23 or 1.7e-5 < M

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

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

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

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

                    \[\leadsto e^{-1 \cdot {M}^{2}} \cdot \cos M \]
                  7. Step-by-step derivation
                    1. Applied rewrites98.3%

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

                    if -4.49999999999999979e23 < M < 1.7e-5

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

                      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \left(K \cdot \left(e^{\left|m - n\right| - \left(\ell + {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}\right)} \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) \cdot e^{\left|m - n\right| - \left(\ell + {\left(\frac{1}{2} \cdot \left(m + n\right) - M\right)}^{2}\right)}} \]
                    4. Applied rewrites85.6%

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

                      \[\leadsto e^{\left|m - n\right| - \left({\left(\mathsf{fma}\left(\frac{1}{2}, n + m, -M\right)\right)}^{2} + \ell\right)} \cdot \left(1 + \color{blue}{\frac{1}{2} \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\right)}\right) \]
                    6. Step-by-step derivation
                      1. Applied rewrites85.6%

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

                      \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -4.5 \cdot 10^{+23} \lor \neg \left(M \leq 1.7 \cdot 10^{-5}\right):\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \cos M\\ \mathbf{else}:\\ \;\;\;\;e^{\left|n - m\right| - \left({\left(\mathsf{fma}\left(0.5, n + m, -M\right)\right)}^{2} + \ell\right)} \cdot \mathsf{fma}\left(\left(M \cdot \left(n + m\right)\right) \cdot K, 0.5, 1\right)\\ \end{array} \]
                    9. Add Preprocessing

                    Alternative 6: 78.0% accurate, 1.5× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(m \cdot m\right) \cdot -0.25} \cdot \cos M\\ t_1 := e^{\left(-M\right) \cdot M} \cdot \cos M\\ \mathbf{if}\;M \leq -0.0075:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq -9.6 \cdot 10^{-137}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 8.2 \cdot 10^{-202}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 5.6 \cdot 10^{-8}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
                    (FPCore (K m n M l)
                     :precision binary64
                     (let* ((t_0 (* (exp (* (* m m) -0.25)) (cos M)))
                            (t_1 (* (exp (* (- M) M)) (cos M))))
                       (if (<= M -0.0075)
                         t_1
                         (if (<= M -9.6e-137)
                           t_0
                           (if (<= M 8.2e-202)
                             (* (* (* M M) -0.5) (exp (- l)))
                             (if (<= M 5.6e-8) t_0 t_1))))))
                    double code(double K, double m, double n, double M, double l) {
                    	double t_0 = exp(((m * m) * -0.25)) * cos(M);
                    	double t_1 = exp((-M * M)) * cos(M);
                    	double tmp;
                    	if (M <= -0.0075) {
                    		tmp = t_1;
                    	} else if (M <= -9.6e-137) {
                    		tmp = t_0;
                    	} else if (M <= 8.2e-202) {
                    		tmp = ((M * M) * -0.5) * exp(-l);
                    	} else if (M <= 5.6e-8) {
                    		tmp = t_0;
                    	} else {
                    		tmp = t_1;
                    	}
                    	return tmp;
                    }
                    
                    real(8) function code(k, m, n, m_1, l)
                        real(8), intent (in) :: k
                        real(8), intent (in) :: m
                        real(8), intent (in) :: n
                        real(8), intent (in) :: m_1
                        real(8), intent (in) :: l
                        real(8) :: t_0
                        real(8) :: t_1
                        real(8) :: tmp
                        t_0 = exp(((m * m) * (-0.25d0))) * cos(m_1)
                        t_1 = exp((-m_1 * m_1)) * cos(m_1)
                        if (m_1 <= (-0.0075d0)) then
                            tmp = t_1
                        else if (m_1 <= (-9.6d-137)) then
                            tmp = t_0
                        else if (m_1 <= 8.2d-202) then
                            tmp = ((m_1 * m_1) * (-0.5d0)) * exp(-l)
                        else if (m_1 <= 5.6d-8) then
                            tmp = t_0
                        else
                            tmp = t_1
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double K, double m, double n, double M, double l) {
                    	double t_0 = Math.exp(((m * m) * -0.25)) * Math.cos(M);
                    	double t_1 = Math.exp((-M * M)) * Math.cos(M);
                    	double tmp;
                    	if (M <= -0.0075) {
                    		tmp = t_1;
                    	} else if (M <= -9.6e-137) {
                    		tmp = t_0;
                    	} else if (M <= 8.2e-202) {
                    		tmp = ((M * M) * -0.5) * Math.exp(-l);
                    	} else if (M <= 5.6e-8) {
                    		tmp = t_0;
                    	} else {
                    		tmp = t_1;
                    	}
                    	return tmp;
                    }
                    
                    def code(K, m, n, M, l):
                    	t_0 = math.exp(((m * m) * -0.25)) * math.cos(M)
                    	t_1 = math.exp((-M * M)) * math.cos(M)
                    	tmp = 0
                    	if M <= -0.0075:
                    		tmp = t_1
                    	elif M <= -9.6e-137:
                    		tmp = t_0
                    	elif M <= 8.2e-202:
                    		tmp = ((M * M) * -0.5) * math.exp(-l)
                    	elif M <= 5.6e-8:
                    		tmp = t_0
                    	else:
                    		tmp = t_1
                    	return tmp
                    
                    function code(K, m, n, M, l)
                    	t_0 = Float64(exp(Float64(Float64(m * m) * -0.25)) * cos(M))
                    	t_1 = Float64(exp(Float64(Float64(-M) * M)) * cos(M))
                    	tmp = 0.0
                    	if (M <= -0.0075)
                    		tmp = t_1;
                    	elseif (M <= -9.6e-137)
                    		tmp = t_0;
                    	elseif (M <= 8.2e-202)
                    		tmp = Float64(Float64(Float64(M * M) * -0.5) * exp(Float64(-l)));
                    	elseif (M <= 5.6e-8)
                    		tmp = t_0;
                    	else
                    		tmp = t_1;
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(K, m, n, M, l)
                    	t_0 = exp(((m * m) * -0.25)) * cos(M);
                    	t_1 = exp((-M * M)) * cos(M);
                    	tmp = 0.0;
                    	if (M <= -0.0075)
                    		tmp = t_1;
                    	elseif (M <= -9.6e-137)
                    		tmp = t_0;
                    	elseif (M <= 8.2e-202)
                    		tmp = ((M * M) * -0.5) * exp(-l);
                    	elseif (M <= 5.6e-8)
                    		tmp = t_0;
                    	else
                    		tmp = t_1;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision] * N[Cos[M], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * N[Cos[M], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -0.0075], t$95$1, If[LessEqual[M, -9.6e-137], t$95$0, If[LessEqual[M, 8.2e-202], N[(N[(N[(M * M), $MachinePrecision] * -0.5), $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 5.6e-8], t$95$0, t$95$1]]]]]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    t_0 := e^{\left(m \cdot m\right) \cdot -0.25} \cdot \cos M\\
                    t_1 := e^{\left(-M\right) \cdot M} \cdot \cos M\\
                    \mathbf{if}\;M \leq -0.0075:\\
                    \;\;\;\;t\_1\\
                    
                    \mathbf{elif}\;M \leq -9.6 \cdot 10^{-137}:\\
                    \;\;\;\;t\_0\\
                    
                    \mathbf{elif}\;M \leq 8.2 \cdot 10^{-202}:\\
                    \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\
                    
                    \mathbf{elif}\;M \leq 5.6 \cdot 10^{-8}:\\
                    \;\;\;\;t\_0\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;t\_1\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 3 regimes
                    2. if M < -0.0074999999999999997 or 5.5999999999999999e-8 < M

                      1. Initial program 81.5%

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

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

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

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

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

                        \[\leadsto e^{-1 \cdot {M}^{2}} \cdot \cos M \]
                      7. Step-by-step derivation
                        1. Applied rewrites96.1%

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

                        if -0.0074999999999999997 < M < -9.6000000000000002e-137 or 8.2000000000000008e-202 < M < 5.5999999999999999e-8

                        1. Initial program 68.7%

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

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

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

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

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

                          \[\leadsto e^{\frac{-1}{4} \cdot {m}^{2}} \cdot \cos M \]
                        7. Step-by-step derivation
                          1. Applied rewrites57.8%

                            \[\leadsto e^{\left(m \cdot m\right) \cdot -0.25} \cdot \cos M \]

                          if -9.6000000000000002e-137 < M < 8.2000000000000008e-202

                          1. Initial program 77.9%

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

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

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

                            \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
                          7. Step-by-step derivation
                            1. cos-negN/A

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

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

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

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

                              \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]
                            2. Taylor expanded in M around inf

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

                                \[\leadsto \left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell} \]
                            4. Recombined 3 regimes into one program.
                            5. Add Preprocessing

                            Alternative 7: 72.2% accurate, 1.6× speedup?

                            \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := e^{\left(-M\right) \cdot M} \cdot \cos M\\ \mathbf{if}\;M \leq -1.05 \cdot 10^{-20}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq 1.35 \cdot 10^{-200}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t\_0\\ \mathbf{elif}\;M \leq 1.7 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(M \cdot M, -0.5, 1\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
                            (FPCore (K m n M l)
                             :precision binary64
                             (let* ((t_0 (exp (- l))) (t_1 (* (exp (* (- M) M)) (cos M))))
                               (if (<= M -1.05e-20)
                                 t_1
                                 (if (<= M 1.35e-200)
                                   (* (* (* M M) -0.5) t_0)
                                   (if (<= M 1.7e-5) (* (fma (* M M) -0.5 1.0) t_0) t_1)))))
                            double code(double K, double m, double n, double M, double l) {
                            	double t_0 = exp(-l);
                            	double t_1 = exp((-M * M)) * cos(M);
                            	double tmp;
                            	if (M <= -1.05e-20) {
                            		tmp = t_1;
                            	} else if (M <= 1.35e-200) {
                            		tmp = ((M * M) * -0.5) * t_0;
                            	} else if (M <= 1.7e-5) {
                            		tmp = fma((M * M), -0.5, 1.0) * t_0;
                            	} else {
                            		tmp = t_1;
                            	}
                            	return tmp;
                            }
                            
                            function code(K, m, n, M, l)
                            	t_0 = exp(Float64(-l))
                            	t_1 = Float64(exp(Float64(Float64(-M) * M)) * cos(M))
                            	tmp = 0.0
                            	if (M <= -1.05e-20)
                            		tmp = t_1;
                            	elseif (M <= 1.35e-200)
                            		tmp = Float64(Float64(Float64(M * M) * -0.5) * t_0);
                            	elseif (M <= 1.7e-5)
                            		tmp = Float64(fma(Float64(M * M), -0.5, 1.0) * t_0);
                            	else
                            		tmp = t_1;
                            	end
                            	return tmp
                            end
                            
                            code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * N[Cos[M], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -1.05e-20], t$95$1, If[LessEqual[M, 1.35e-200], N[(N[(N[(M * M), $MachinePrecision] * -0.5), $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[M, 1.7e-5], N[(N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision], t$95$1]]]]]
                            
                            \begin{array}{l}
                            
                            \\
                            \begin{array}{l}
                            t_0 := e^{-\ell}\\
                            t_1 := e^{\left(-M\right) \cdot M} \cdot \cos M\\
                            \mathbf{if}\;M \leq -1.05 \cdot 10^{-20}:\\
                            \;\;\;\;t\_1\\
                            
                            \mathbf{elif}\;M \leq 1.35 \cdot 10^{-200}:\\
                            \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t\_0\\
                            
                            \mathbf{elif}\;M \leq 1.7 \cdot 10^{-5}:\\
                            \;\;\;\;\mathsf{fma}\left(M \cdot M, -0.5, 1\right) \cdot t\_0\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;t\_1\\
                            
                            
                            \end{array}
                            \end{array}
                            
                            Derivation
                            1. Split input into 3 regimes
                            2. if M < -1.0499999999999999e-20 or 1.7e-5 < M

                              1. Initial program 80.8%

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

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

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

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

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

                                \[\leadsto e^{-1 \cdot {M}^{2}} \cdot \cos M \]
                              7. Step-by-step derivation
                                1. Applied rewrites96.1%

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

                                if -1.0499999999999999e-20 < M < 1.3500000000000001e-200

                                1. Initial program 73.6%

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

                                  \[\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.f6437.9

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

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

                                  \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
                                7. Step-by-step derivation
                                  1. cos-negN/A

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

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

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

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

                                    \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]
                                  2. Taylor expanded in M around inf

                                    \[\leadsto \left(\frac{-1}{2} \cdot {M}^{\color{blue}{2}}\right) \cdot e^{-\ell} \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites55.6%

                                      \[\leadsto \left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell} \]

                                    if 1.3500000000000001e-200 < M < 1.7e-5

                                    1. Initial program 73.9%

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

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

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

                                      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
                                    7. Step-by-step derivation
                                      1. cos-negN/A

                                        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
                                      2. lower-cos.f6449.0

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

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

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

                                        \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]
                                    11. Recombined 3 regimes into one program.
                                    12. Add Preprocessing

                                    Alternative 8: 63.8% accurate, 1.6× speedup?

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

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

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

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

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

                                        \[\leadsto e^{\frac{-1}{4} \cdot {m}^{2}} \cdot \cos M \]
                                      7. Step-by-step derivation
                                        1. Applied rewrites55.5%

                                          \[\leadsto e^{\left(m \cdot m\right) \cdot -0.25} \cdot \cos M \]

                                        if 7.99999999999999937e-226 < n < 3.5499999999999998

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

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

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

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

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

                                          \[\leadsto e^{\left|m - n\right| - {M}^{2}} \cdot \cos M \]
                                        7. Step-by-step derivation
                                          1. Applied rewrites58.5%

                                            \[\leadsto e^{\left|m - n\right| - M \cdot M} \cdot \cos M \]

                                          if 3.5499999999999998 < n

                                          1. Initial program 72.3%

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

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

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

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

                                              \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
                                            4. lower-*.f6472.3

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

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

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

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

                                              \[\leadsto \color{blue}{\cos M} \cdot e^{\left(n \cdot n\right) \cdot -0.25} \]
                                          8. Applied rewrites98.5%

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

                                          \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 8 \cdot 10^{-226}:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25} \cdot \cos M\\ \mathbf{elif}\;n \leq 3.55:\\ \;\;\;\;e^{\left|n - m\right| - M \cdot M} \cdot \cos M\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]
                                        10. Add Preprocessing

                                        Alternative 9: 64.8% accurate, 1.6× speedup?

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

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

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

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

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

                                            \[\leadsto e^{\frac{-1}{4} \cdot {m}^{2}} \cdot \cos M \]
                                          7. Step-by-step derivation
                                            1. Applied rewrites55.5%

                                              \[\leadsto e^{\left(m \cdot m\right) \cdot -0.25} \cdot \cos M \]

                                            if 5.60000000000000016e-226 < n < 3.5499999999999998

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

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

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

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

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

                                              \[\leadsto e^{-1 \cdot {M}^{2}} \cdot \cos M \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites58.1%

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

                                              if 3.5499999999999998 < n

                                              1. Initial program 72.3%

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

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

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

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

                                                  \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
                                                4. lower-*.f6472.3

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

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

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

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

                                                  \[\leadsto \color{blue}{\cos M} \cdot e^{\left(n \cdot n\right) \cdot -0.25} \]
                                              8. Applied rewrites98.5%

                                                \[\leadsto \color{blue}{\cos M} \cdot e^{\left(n \cdot n\right) \cdot -0.25} \]
                                            8. Recombined 3 regimes into one program.
                                            9. Add Preprocessing

                                            Alternative 10: 39.7% accurate, 1.6× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ \mathbf{if}\;M \leq -7.5 \cdot 10^{-165} \lor \neg \left(M \leq 1.35 \cdot 10^{-200}\right):\\ \;\;\;\;\cos M \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t\_0\\ \end{array} \end{array} \]
                                            (FPCore (K m n M l)
                                             :precision binary64
                                             (let* ((t_0 (exp (- l))))
                                               (if (or (<= M -7.5e-165) (not (<= M 1.35e-200)))
                                                 (* (cos M) t_0)
                                                 (* (* (* M M) -0.5) t_0))))
                                            double code(double K, double m, double n, double M, double l) {
                                            	double t_0 = exp(-l);
                                            	double tmp;
                                            	if ((M <= -7.5e-165) || !(M <= 1.35e-200)) {
                                            		tmp = cos(M) * t_0;
                                            	} else {
                                            		tmp = ((M * M) * -0.5) * t_0;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            real(8) function code(k, m, n, m_1, l)
                                                real(8), intent (in) :: k
                                                real(8), intent (in) :: m
                                                real(8), intent (in) :: n
                                                real(8), intent (in) :: m_1
                                                real(8), intent (in) :: l
                                                real(8) :: t_0
                                                real(8) :: tmp
                                                t_0 = exp(-l)
                                                if ((m_1 <= (-7.5d-165)) .or. (.not. (m_1 <= 1.35d-200))) then
                                                    tmp = cos(m_1) * t_0
                                                else
                                                    tmp = ((m_1 * m_1) * (-0.5d0)) * t_0
                                                end if
                                                code = tmp
                                            end function
                                            
                                            public static double code(double K, double m, double n, double M, double l) {
                                            	double t_0 = Math.exp(-l);
                                            	double tmp;
                                            	if ((M <= -7.5e-165) || !(M <= 1.35e-200)) {
                                            		tmp = Math.cos(M) * t_0;
                                            	} else {
                                            		tmp = ((M * M) * -0.5) * t_0;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            def code(K, m, n, M, l):
                                            	t_0 = math.exp(-l)
                                            	tmp = 0
                                            	if (M <= -7.5e-165) or not (M <= 1.35e-200):
                                            		tmp = math.cos(M) * t_0
                                            	else:
                                            		tmp = ((M * M) * -0.5) * t_0
                                            	return tmp
                                            
                                            function code(K, m, n, M, l)
                                            	t_0 = exp(Float64(-l))
                                            	tmp = 0.0
                                            	if ((M <= -7.5e-165) || !(M <= 1.35e-200))
                                            		tmp = Float64(cos(M) * t_0);
                                            	else
                                            		tmp = Float64(Float64(Float64(M * M) * -0.5) * t_0);
                                            	end
                                            	return tmp
                                            end
                                            
                                            function tmp_2 = code(K, m, n, M, l)
                                            	t_0 = exp(-l);
                                            	tmp = 0.0;
                                            	if ((M <= -7.5e-165) || ~((M <= 1.35e-200)))
                                            		tmp = cos(M) * t_0;
                                            	else
                                            		tmp = ((M * M) * -0.5) * t_0;
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, If[Or[LessEqual[M, -7.5e-165], N[Not[LessEqual[M, 1.35e-200]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[(N[(M * M), $MachinePrecision] * -0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            t_0 := e^{-\ell}\\
                                            \mathbf{if}\;M \leq -7.5 \cdot 10^{-165} \lor \neg \left(M \leq 1.35 \cdot 10^{-200}\right):\\
                                            \;\;\;\;\cos M \cdot t\_0\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t\_0\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if M < -7.5000000000000002e-165 or 1.3500000000000001e-200 < M

                                              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 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.f6435.2

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

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

                                                \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
                                              7. Step-by-step derivation
                                                1. cos-negN/A

                                                  \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
                                                2. lower-cos.f6441.5

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

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

                                              if -7.5000000000000002e-165 < M < 1.3500000000000001e-200

                                              1. Initial program 75.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 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.f6434.8

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

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

                                                \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
                                              7. Step-by-step derivation
                                                1. cos-negN/A

                                                  \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
                                                2. lower-cos.f6438.3

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

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

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

                                                  \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]
                                                2. Taylor expanded in M around inf

                                                  \[\leadsto \left(\frac{-1}{2} \cdot {M}^{\color{blue}{2}}\right) \cdot e^{-\ell} \]
                                                3. Step-by-step derivation
                                                  1. Applied rewrites66.5%

                                                    \[\leadsto \left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell} \]
                                                4. Recombined 2 regimes into one program.
                                                5. Final simplification46.7%

                                                  \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -7.5 \cdot 10^{-165} \lor \neg \left(M \leq 1.35 \cdot 10^{-200}\right):\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\ \end{array} \]
                                                6. Add Preprocessing

                                                Alternative 11: 30.0% accurate, 3.0× speedup?

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

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

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

                                                  \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{-\ell} \]
                                                7. Step-by-step derivation
                                                  1. cos-negN/A

                                                    \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
                                                  2. lower-cos.f6440.9

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

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

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

                                                    \[\leadsto \mathsf{fma}\left(M \cdot M, \color{blue}{-0.5}, 1\right) \cdot e^{-\ell} \]
                                                  2. Taylor expanded in M around inf

                                                    \[\leadsto \left(\frac{-1}{2} \cdot {M}^{\color{blue}{2}}\right) \cdot e^{-\ell} \]
                                                  3. Step-by-step derivation
                                                    1. Applied rewrites32.0%

                                                      \[\leadsto \left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell} \]
                                                    2. Add Preprocessing

                                                    Reproduce

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