Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.1% → 96.9%
Time: 10.5s
Alternatives: 13
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 13 alternatives:

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

Initial Program: 76.1% 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.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ e^{\left|n - m\right| - \left({\left(\mathsf{fma}\left(n + m, 0.5, -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 (+ n m) 0.5 (- 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((n + m), 0.5, -M), 2.0) + l))) * cos(M);
}
function code(K, m, n, M, l)
	return Float64(exp(Float64(abs(Float64(n - m)) - Float64((fma(Float64(n + m), 0.5, 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[(N[(n + m), $MachinePrecision] * 0.5 + (-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(n + m, 0.5, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M
\end{array}
Derivation
  1. Initial program 71.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.3%

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

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

Alternative 2: 96.3% accurate, 1.1× speedup?

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

\\
{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - {\left(\mathsf{fma}\left(n + m, 0.5, -M\right)\right)}^{2}\right)}\right)}^{-1} \cdot 1
\end{array}
Derivation
  1. Initial program 71.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.3%

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

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

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

        \[\leadsto \frac{1}{e^{-\left(\left(\left|n - m\right| - \ell\right) - {\left(\mathsf{fma}\left(n + m, 0.5, -M\right)\right)}^{2}\right)}} \cdot 1 \]
      2. Final simplification95.9%

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

      Alternative 3: 75.9% accurate, 1.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ t_1 := \left|n - m\right|\\ t_2 := {\left(e^{-\left(\left(t\_1 - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ t_3 := e^{t\_1 - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot t\_0\\ \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;M \leq -7.5 \cdot 10^{-194}:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;M \leq 1.35 \cdot 10^{-145}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot t\_0\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
      (FPCore (K m n M l)
       :precision binary64
       (let* ((t_0 (fma (* M M) -0.5 1.0))
              (t_1 (fabs (- n m)))
              (t_2 (* (pow (exp (- (- (- t_1 l) (* M M)))) -1.0) 1.0))
              (t_3 (* (exp (- t_1 (+ (* (* m m) 0.25) l))) t_0)))
         (if (<= M -6.5e+109)
           t_2
           (if (<= M -7.5e-194)
             t_3
             (if (<= M 1.35e-145)
               (* (exp (* (* n n) -0.25)) t_0)
               (if (<= M 27.0)
                 t_3
                 (if (<= M 5.4e+106) (* (exp (* (- M) M)) t_0) t_2)))))))
      double code(double K, double m, double n, double M, double l) {
      	double t_0 = fma((M * M), -0.5, 1.0);
      	double t_1 = fabs((n - m));
      	double t_2 = pow(exp(-((t_1 - l) - (M * M))), -1.0) * 1.0;
      	double t_3 = exp((t_1 - (((m * m) * 0.25) + l))) * t_0;
      	double tmp;
      	if (M <= -6.5e+109) {
      		tmp = t_2;
      	} else if (M <= -7.5e-194) {
      		tmp = t_3;
      	} else if (M <= 1.35e-145) {
      		tmp = exp(((n * n) * -0.25)) * t_0;
      	} else if (M <= 27.0) {
      		tmp = t_3;
      	} else if (M <= 5.4e+106) {
      		tmp = exp((-M * M)) * t_0;
      	} else {
      		tmp = t_2;
      	}
      	return tmp;
      }
      
      function code(K, m, n, M, l)
      	t_0 = fma(Float64(M * M), -0.5, 1.0)
      	t_1 = abs(Float64(n - m))
      	t_2 = Float64((exp(Float64(-Float64(Float64(t_1 - l) - Float64(M * M)))) ^ -1.0) * 1.0)
      	t_3 = Float64(exp(Float64(t_1 - Float64(Float64(Float64(m * m) * 0.25) + l))) * t_0)
      	tmp = 0.0
      	if (M <= -6.5e+109)
      		tmp = t_2;
      	elseif (M <= -7.5e-194)
      		tmp = t_3;
      	elseif (M <= 1.35e-145)
      		tmp = Float64(exp(Float64(Float64(n * n) * -0.25)) * t_0);
      	elseif (M <= 27.0)
      		tmp = t_3;
      	elseif (M <= 5.4e+106)
      		tmp = Float64(exp(Float64(Float64(-M) * M)) * t_0);
      	else
      		tmp = t_2;
      	end
      	return tmp
      end
      
      code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[Exp[(-N[(N[(t$95$1 - l), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision])], $MachinePrecision], -1.0], $MachinePrecision] * 1.0), $MachinePrecision]}, Block[{t$95$3 = N[(N[Exp[N[(t$95$1 - N[(N[(N[(m * m), $MachinePrecision] * 0.25), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[M, -6.5e+109], t$95$2, If[LessEqual[M, -7.5e-194], t$95$3, If[LessEqual[M, 1.35e-145], N[(N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[M, 27.0], t$95$3, If[LessEqual[M, 5.4e+106], N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], t$95$2]]]]]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
      t_1 := \left|n - m\right|\\
      t_2 := {\left(e^{-\left(\left(t\_1 - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\
      t_3 := e^{t\_1 - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot t\_0\\
      \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\
      \;\;\;\;t\_2\\
      
      \mathbf{elif}\;M \leq -7.5 \cdot 10^{-194}:\\
      \;\;\;\;t\_3\\
      
      \mathbf{elif}\;M \leq 1.35 \cdot 10^{-145}:\\
      \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot t\_0\\
      
      \mathbf{elif}\;M \leq 27:\\
      \;\;\;\;t\_3\\
      
      \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\
      \;\;\;\;e^{\left(-M\right) \cdot M} \cdot t\_0\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_2\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 4 regimes
      2. if M < -6.5e109 or 5.40000000000000012e106 < M

        1. Initial program 71.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(n + m, 0.5, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M} \]
        6. Step-by-step derivation
          1. Applied rewrites100.0%

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

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

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

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

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

              if -6.5e109 < M < -7.4999999999999998e-194 or 1.35e-145 < M < 27

              1. Initial program 76.4%

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

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

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

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

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

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

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

                  if -7.4999999999999998e-194 < M < 1.35e-145

                  1. Initial program 61.6%

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

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

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

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

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

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

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

                      if 27 < M < 5.40000000000000012e106

                      1. Initial program 71.4%

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

                        \[\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(n + m, 0.5, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M} \]
                      6. Taylor expanded in M around 0

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

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

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

                            \[\leadsto e^{\left(-M\right) \cdot M} \cdot \mathsf{fma}\left(\color{blue}{M} \cdot M, -0.5, 1\right) \]
                        4. Recombined 4 regimes into one program.
                        5. Final simplification76.3%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\ \;\;\;\;{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \mathbf{elif}\;M \leq -7.5 \cdot 10^{-194}:\\ \;\;\;\;e^{\left|n - m\right| - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq 1.35 \cdot 10^{-145}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;e^{\left|n - m\right| - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \end{array} \]
                        6. Add Preprocessing

                        Alternative 4: 75.6% accurate, 1.4× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ t_1 := \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ t_2 := e^{\left(-M\right) \cdot M} \cdot t\_1\\ \mathbf{if}\;M \leq -2 \cdot 10^{+151}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq -0.0017:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;M \leq -1 \cdot 10^{-183}:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25} \cdot t\_1\\ \mathbf{elif}\;M \leq 0.0082:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot t\_1\\ \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
                        (FPCore (K m n M l)
                         :precision binary64
                         (let* ((t_0 (* (pow (exp (- (- (- (fabs (- n m)) l) (* M M)))) -1.0) 1.0))
                                (t_1 (fma (* M M) -0.5 1.0))
                                (t_2 (* (exp (* (- M) M)) t_1)))
                           (if (<= M -2e+151)
                             t_0
                             (if (<= M -0.0017)
                               t_2
                               (if (<= M -1e-183)
                                 (* (exp (* (* m m) -0.25)) t_1)
                                 (if (<= M 0.0082)
                                   (* (exp (* (* n n) -0.25)) t_1)
                                   (if (<= M 5.4e+106) t_2 t_0)))))))
                        double code(double K, double m, double n, double M, double l) {
                        	double t_0 = pow(exp(-((fabs((n - m)) - l) - (M * M))), -1.0) * 1.0;
                        	double t_1 = fma((M * M), -0.5, 1.0);
                        	double t_2 = exp((-M * M)) * t_1;
                        	double tmp;
                        	if (M <= -2e+151) {
                        		tmp = t_0;
                        	} else if (M <= -0.0017) {
                        		tmp = t_2;
                        	} else if (M <= -1e-183) {
                        		tmp = exp(((m * m) * -0.25)) * t_1;
                        	} else if (M <= 0.0082) {
                        		tmp = exp(((n * n) * -0.25)) * t_1;
                        	} else if (M <= 5.4e+106) {
                        		tmp = t_2;
                        	} else {
                        		tmp = t_0;
                        	}
                        	return tmp;
                        }
                        
                        function code(K, m, n, M, l)
                        	t_0 = Float64((exp(Float64(-Float64(Float64(abs(Float64(n - m)) - l) - Float64(M * M)))) ^ -1.0) * 1.0)
                        	t_1 = fma(Float64(M * M), -0.5, 1.0)
                        	t_2 = Float64(exp(Float64(Float64(-M) * M)) * t_1)
                        	tmp = 0.0
                        	if (M <= -2e+151)
                        		tmp = t_0;
                        	elseif (M <= -0.0017)
                        		tmp = t_2;
                        	elseif (M <= -1e-183)
                        		tmp = Float64(exp(Float64(Float64(m * m) * -0.25)) * t_1);
                        	elseif (M <= 0.0082)
                        		tmp = Float64(exp(Float64(Float64(n * n) * -0.25)) * t_1);
                        	elseif (M <= 5.4e+106)
                        		tmp = t_2;
                        	else
                        		tmp = t_0;
                        	end
                        	return tmp
                        end
                        
                        code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Power[N[Exp[(-N[(N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision])], $MachinePrecision], -1.0], $MachinePrecision] * 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[M, -2e+151], t$95$0, If[LessEqual[M, -0.0017], t$95$2, If[LessEqual[M, -1e-183], N[(N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[M, 0.0082], N[(N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[M, 5.4e+106], t$95$2, t$95$0]]]]]]]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        t_0 := {\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\
                        t_1 := \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
                        t_2 := e^{\left(-M\right) \cdot M} \cdot t\_1\\
                        \mathbf{if}\;M \leq -2 \cdot 10^{+151}:\\
                        \;\;\;\;t\_0\\
                        
                        \mathbf{elif}\;M \leq -0.0017:\\
                        \;\;\;\;t\_2\\
                        
                        \mathbf{elif}\;M \leq -1 \cdot 10^{-183}:\\
                        \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25} \cdot t\_1\\
                        
                        \mathbf{elif}\;M \leq 0.0082:\\
                        \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot t\_1\\
                        
                        \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\
                        \;\;\;\;t\_2\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;t\_0\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 4 regimes
                        2. if M < -2.00000000000000003e151 or 5.40000000000000012e106 < M

                          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 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(n + m, 0.5, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M} \]
                          6. Step-by-step derivation
                            1. Applied rewrites100.0%

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

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

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

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

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

                                if -2.00000000000000003e151 < M < -0.00169999999999999991 or 0.00820000000000000069 < M < 5.40000000000000012e106

                                1. Initial program 68.3%

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

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

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

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

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

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

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

                                    if -0.00169999999999999991 < M < -1.00000000000000001e-183

                                    1. Initial program 85.4%

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

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

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

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

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

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

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

                                        if -1.00000000000000001e-183 < M < 0.00820000000000000069

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

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

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

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

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

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

                                            \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -2 \cdot 10^{+151}:\\ \;\;\;\;{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \mathbf{elif}\;M \leq -0.0017:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq -1 \cdot 10^{-183}:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq 0.0082:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \end{array} \]
                                          6. Add Preprocessing

                                          Alternative 5: 87.3% accurate, 1.4× speedup?

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

                                            1. Initial program 63.4%

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

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

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

                                              \[\leadsto e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites95.8%

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

                                              if -1.55e-6 < m

                                              1. Initial program 74.1%

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

                                                \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right) \cdot e^{\left|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(n + m, 0.5, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M} \]
                                              6. Step-by-step derivation
                                                1. Applied rewrites96.0%

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

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

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

                                                    \[\leadsto \frac{1}{e^{-\left(\left(\left|n - m\right| - \ell\right) - \left(m \cdot \left(\frac{1}{2} \cdot n - M\right) + {\left(\frac{1}{2} \cdot n - M\right)}^{2}\right)\right)}} \cdot 1 \]
                                                  3. Step-by-step derivation
                                                    1. Applied rewrites84.8%

                                                      \[\leadsto \frac{1}{e^{-\left(\left(\left|n - m\right| - \ell\right) - \left(0.5 \cdot n - M\right) \cdot \left(m + \left(0.5 \cdot n - M\right)\right)\right)}} \cdot 1 \]
                                                  4. Recombined 2 regimes into one program.
                                                  5. Final simplification87.8%

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

                                                  Alternative 6: 87.3% accurate, 1.4× speedup?

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

                                                    1. Initial program 63.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 rewrites98.5%

                                                      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left({\left(\mathsf{fma}\left(n + m, 0.5, -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 rewrites95.7%

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

                                                      if -610 < m

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

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

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

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

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

                                                            \[\leadsto \frac{1}{e^{-\left(\left(\left|n - m\right| - \ell\right) - \left(m \cdot \left(\frac{1}{2} \cdot n - M\right) + {\left(\frac{1}{2} \cdot n - M\right)}^{2}\right)\right)}} \cdot 1 \]
                                                          3. Step-by-step derivation
                                                            1. Applied rewrites84.5%

                                                              \[\leadsto \frac{1}{e^{-\left(\left(\left|n - m\right| - \ell\right) - \left(0.5 \cdot n - M\right) \cdot \left(m + \left(0.5 \cdot n - M\right)\right)\right)}} \cdot 1 \]
                                                          4. Recombined 2 regimes into one program.
                                                          5. Final simplification87.5%

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

                                                          Alternative 7: 81.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

                                                                if -8.6e95 < m

                                                                1. Initial program 73.9%

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

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

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

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

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

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

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

                                                                        \[\leadsto \frac{1}{e^{-\left(\left(\left|n - m\right| - \ell\right) - \left(0.5 \cdot n - M\right) \cdot \left(m + \left(0.5 \cdot n - M\right)\right)\right)}} \cdot 1 \]
                                                                    4. Recombined 2 regimes into one program.
                                                                    5. Final simplification81.2%

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

                                                                    Alternative 8: 77.9% accurate, 1.4× speedup?

                                                                    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ t_1 := \left|n - m\right|\\ t_2 := {\left(e^{-\left(\left(t\_1 - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;M \leq -2 \cdot 10^{-211}:\\ \;\;\;\;e^{t\_1 - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot t\_0\\ \mathbf{elif}\;M \leq 0.0082:\\ \;\;\;\;e^{t\_1 - \left(\left(n \cdot n\right) \cdot 0.25 + \ell\right)} \cdot t\_0\\ \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
                                                                    (FPCore (K m n M l)
                                                                     :precision binary64
                                                                     (let* ((t_0 (fma (* M M) -0.5 1.0))
                                                                            (t_1 (fabs (- n m)))
                                                                            (t_2 (* (pow (exp (- (- (- t_1 l) (* M M)))) -1.0) 1.0)))
                                                                       (if (<= M -6.5e+109)
                                                                         t_2
                                                                         (if (<= M -2e-211)
                                                                           (* (exp (- t_1 (+ (* (* m m) 0.25) l))) t_0)
                                                                           (if (<= M 0.0082)
                                                                             (* (exp (- t_1 (+ (* (* n n) 0.25) l))) t_0)
                                                                             (if (<= M 5.4e+106) (* (exp (* (- M) M)) t_0) t_2))))))
                                                                    double code(double K, double m, double n, double M, double l) {
                                                                    	double t_0 = fma((M * M), -0.5, 1.0);
                                                                    	double t_1 = fabs((n - m));
                                                                    	double t_2 = pow(exp(-((t_1 - l) - (M * M))), -1.0) * 1.0;
                                                                    	double tmp;
                                                                    	if (M <= -6.5e+109) {
                                                                    		tmp = t_2;
                                                                    	} else if (M <= -2e-211) {
                                                                    		tmp = exp((t_1 - (((m * m) * 0.25) + l))) * t_0;
                                                                    	} else if (M <= 0.0082) {
                                                                    		tmp = exp((t_1 - (((n * n) * 0.25) + l))) * t_0;
                                                                    	} else if (M <= 5.4e+106) {
                                                                    		tmp = exp((-M * M)) * t_0;
                                                                    	} else {
                                                                    		tmp = t_2;
                                                                    	}
                                                                    	return tmp;
                                                                    }
                                                                    
                                                                    function code(K, m, n, M, l)
                                                                    	t_0 = fma(Float64(M * M), -0.5, 1.0)
                                                                    	t_1 = abs(Float64(n - m))
                                                                    	t_2 = Float64((exp(Float64(-Float64(Float64(t_1 - l) - Float64(M * M)))) ^ -1.0) * 1.0)
                                                                    	tmp = 0.0
                                                                    	if (M <= -6.5e+109)
                                                                    		tmp = t_2;
                                                                    	elseif (M <= -2e-211)
                                                                    		tmp = Float64(exp(Float64(t_1 - Float64(Float64(Float64(m * m) * 0.25) + l))) * t_0);
                                                                    	elseif (M <= 0.0082)
                                                                    		tmp = Float64(exp(Float64(t_1 - Float64(Float64(Float64(n * n) * 0.25) + l))) * t_0);
                                                                    	elseif (M <= 5.4e+106)
                                                                    		tmp = Float64(exp(Float64(Float64(-M) * M)) * t_0);
                                                                    	else
                                                                    		tmp = t_2;
                                                                    	end
                                                                    	return tmp
                                                                    end
                                                                    
                                                                    code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[Exp[(-N[(N[(t$95$1 - l), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision])], $MachinePrecision], -1.0], $MachinePrecision] * 1.0), $MachinePrecision]}, If[LessEqual[M, -6.5e+109], t$95$2, If[LessEqual[M, -2e-211], N[(N[Exp[N[(t$95$1 - N[(N[(N[(m * m), $MachinePrecision] * 0.25), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[M, 0.0082], N[(N[Exp[N[(t$95$1 - N[(N[(N[(n * n), $MachinePrecision] * 0.25), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[M, 5.4e+106], N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], t$95$2]]]]]]]
                                                                    
                                                                    \begin{array}{l}
                                                                    
                                                                    \\
                                                                    \begin{array}{l}
                                                                    t_0 := \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
                                                                    t_1 := \left|n - m\right|\\
                                                                    t_2 := {\left(e^{-\left(\left(t\_1 - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\
                                                                    \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\
                                                                    \;\;\;\;t\_2\\
                                                                    
                                                                    \mathbf{elif}\;M \leq -2 \cdot 10^{-211}:\\
                                                                    \;\;\;\;e^{t\_1 - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot t\_0\\
                                                                    
                                                                    \mathbf{elif}\;M \leq 0.0082:\\
                                                                    \;\;\;\;e^{t\_1 - \left(\left(n \cdot n\right) \cdot 0.25 + \ell\right)} \cdot t\_0\\
                                                                    
                                                                    \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\
                                                                    \;\;\;\;e^{\left(-M\right) \cdot M} \cdot t\_0\\
                                                                    
                                                                    \mathbf{else}:\\
                                                                    \;\;\;\;t\_2\\
                                                                    
                                                                    
                                                                    \end{array}
                                                                    \end{array}
                                                                    
                                                                    Derivation
                                                                    1. Split input into 4 regimes
                                                                    2. if M < -6.5e109 or 5.40000000000000012e106 < M

                                                                      1. Initial program 71.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(n + m, 0.5, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M} \]
                                                                      6. Step-by-step derivation
                                                                        1. Applied rewrites100.0%

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

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

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

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

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

                                                                            if -6.5e109 < M < -2.00000000000000017e-211

                                                                            1. Initial program 78.0%

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

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

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

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

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

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

                                                                                if -2.00000000000000017e-211 < M < 0.00820000000000000069

                                                                                1. Initial program 64.3%

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

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

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

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

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

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

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

                                                                                    if 0.00820000000000000069 < M < 5.40000000000000012e106

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

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

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

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

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

                                                                                          \[\leadsto e^{\left(-M\right) \cdot M} \cdot \mathsf{fma}\left(\color{blue}{M} \cdot M, -0.5, 1\right) \]
                                                                                      4. Recombined 4 regimes into one program.
                                                                                      5. Final simplification78.9%

                                                                                        \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\ \;\;\;\;{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \mathbf{elif}\;M \leq -2 \cdot 10^{-211}:\\ \;\;\;\;e^{\left|n - m\right| - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq 0.0082:\\ \;\;\;\;e^{\left|n - m\right| - \left(\left(n \cdot n\right) \cdot 0.25 + \ell\right)} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq 5.4 \cdot 10^{+106}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \end{array} \]
                                                                                      6. Add Preprocessing

                                                                                      Alternative 9: 77.1% accurate, 1.5× speedup?

                                                                                      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ t_1 := 0.5 \cdot n - M\\ t_2 := \left|n - m\right|\\ t_3 := {\left(e^{-\left(\left(t\_2 - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;M \leq -5 \cdot 10^{-184}:\\ \;\;\;\;e^{t\_2 - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot t\_0\\ \mathbf{elif}\;M \leq 4.9 \cdot 10^{+106}:\\ \;\;\;\;e^{t\_2 - \left(t\_1 \cdot \left(m + t\_1\right) + \ell\right)} \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
                                                                                      (FPCore (K m n M l)
                                                                                       :precision binary64
                                                                                       (let* ((t_0 (fma (* M M) -0.5 1.0))
                                                                                              (t_1 (- (* 0.5 n) M))
                                                                                              (t_2 (fabs (- n m)))
                                                                                              (t_3 (* (pow (exp (- (- (- t_2 l) (* M M)))) -1.0) 1.0)))
                                                                                         (if (<= M -6.5e+109)
                                                                                           t_3
                                                                                           (if (<= M -5e-184)
                                                                                             (* (exp (- t_2 (+ (* (* m m) 0.25) l))) t_0)
                                                                                             (if (<= M 4.9e+106)
                                                                                               (* (exp (- t_2 (+ (* t_1 (+ m t_1)) l))) t_0)
                                                                                               t_3)))))
                                                                                      double code(double K, double m, double n, double M, double l) {
                                                                                      	double t_0 = fma((M * M), -0.5, 1.0);
                                                                                      	double t_1 = (0.5 * n) - M;
                                                                                      	double t_2 = fabs((n - m));
                                                                                      	double t_3 = pow(exp(-((t_2 - l) - (M * M))), -1.0) * 1.0;
                                                                                      	double tmp;
                                                                                      	if (M <= -6.5e+109) {
                                                                                      		tmp = t_3;
                                                                                      	} else if (M <= -5e-184) {
                                                                                      		tmp = exp((t_2 - (((m * m) * 0.25) + l))) * t_0;
                                                                                      	} else if (M <= 4.9e+106) {
                                                                                      		tmp = exp((t_2 - ((t_1 * (m + t_1)) + l))) * t_0;
                                                                                      	} else {
                                                                                      		tmp = t_3;
                                                                                      	}
                                                                                      	return tmp;
                                                                                      }
                                                                                      
                                                                                      function code(K, m, n, M, l)
                                                                                      	t_0 = fma(Float64(M * M), -0.5, 1.0)
                                                                                      	t_1 = Float64(Float64(0.5 * n) - M)
                                                                                      	t_2 = abs(Float64(n - m))
                                                                                      	t_3 = Float64((exp(Float64(-Float64(Float64(t_2 - l) - Float64(M * M)))) ^ -1.0) * 1.0)
                                                                                      	tmp = 0.0
                                                                                      	if (M <= -6.5e+109)
                                                                                      		tmp = t_3;
                                                                                      	elseif (M <= -5e-184)
                                                                                      		tmp = Float64(exp(Float64(t_2 - Float64(Float64(Float64(m * m) * 0.25) + l))) * t_0);
                                                                                      	elseif (M <= 4.9e+106)
                                                                                      		tmp = Float64(exp(Float64(t_2 - Float64(Float64(t_1 * Float64(m + t_1)) + l))) * t_0);
                                                                                      	else
                                                                                      		tmp = t_3;
                                                                                      	end
                                                                                      	return tmp
                                                                                      end
                                                                                      
                                                                                      code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * n), $MachinePrecision] - M), $MachinePrecision]}, Block[{t$95$2 = N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[Exp[(-N[(N[(t$95$2 - l), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision])], $MachinePrecision], -1.0], $MachinePrecision] * 1.0), $MachinePrecision]}, If[LessEqual[M, -6.5e+109], t$95$3, If[LessEqual[M, -5e-184], N[(N[Exp[N[(t$95$2 - N[(N[(N[(m * m), $MachinePrecision] * 0.25), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[M, 4.9e+106], N[(N[Exp[N[(t$95$2 - N[(N[(t$95$1 * N[(m + t$95$1), $MachinePrecision]), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], t$95$3]]]]]]]
                                                                                      
                                                                                      \begin{array}{l}
                                                                                      
                                                                                      \\
                                                                                      \begin{array}{l}
                                                                                      t_0 := \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
                                                                                      t_1 := 0.5 \cdot n - M\\
                                                                                      t_2 := \left|n - m\right|\\
                                                                                      t_3 := {\left(e^{-\left(\left(t\_2 - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\
                                                                                      \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\
                                                                                      \;\;\;\;t\_3\\
                                                                                      
                                                                                      \mathbf{elif}\;M \leq -5 \cdot 10^{-184}:\\
                                                                                      \;\;\;\;e^{t\_2 - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot t\_0\\
                                                                                      
                                                                                      \mathbf{elif}\;M \leq 4.9 \cdot 10^{+106}:\\
                                                                                      \;\;\;\;e^{t\_2 - \left(t\_1 \cdot \left(m + t\_1\right) + \ell\right)} \cdot t\_0\\
                                                                                      
                                                                                      \mathbf{else}:\\
                                                                                      \;\;\;\;t\_3\\
                                                                                      
                                                                                      
                                                                                      \end{array}
                                                                                      \end{array}
                                                                                      
                                                                                      Derivation
                                                                                      1. Split input into 3 regimes
                                                                                      2. if M < -6.5e109 or 4.89999999999999998e106 < M

                                                                                        1. Initial program 71.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(n + m, 0.5, -M\right)\right)}^{2} + \ell\right)} \cdot \cos M} \]
                                                                                        6. Step-by-step derivation
                                                                                          1. Applied rewrites100.0%

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

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

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

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

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

                                                                                              if -6.5e109 < M < -5.00000000000000003e-184

                                                                                              1. Initial program 78.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 rewrites91.6%

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

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

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

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

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

                                                                                                  if -5.00000000000000003e-184 < M < 4.89999999999999998e106

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

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

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

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

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

                                                                                                        \[\leadsto e^{\left|m - n\right| - \left(\left(0.5 \cdot n - M\right) \cdot \left(m + \left(0.5 \cdot n - M\right)\right) + \ell\right)} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right) \]
                                                                                                    4. Recombined 3 regimes into one program.
                                                                                                    5. Final simplification79.0%

                                                                                                      \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -6.5 \cdot 10^{+109}:\\ \;\;\;\;{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \mathbf{elif}\;M \leq -5 \cdot 10^{-184}:\\ \;\;\;\;e^{\left|n - m\right| - \left(\left(m \cdot m\right) \cdot 0.25 + \ell\right)} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;M \leq 4.9 \cdot 10^{+106}:\\ \;\;\;\;e^{\left|n - m\right| - \left(\left(0.5 \cdot n - M\right) \cdot \left(m + \left(0.5 \cdot n - M\right)\right) + \ell\right)} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{-\left(\left(\left|n - m\right| - \ell\right) - M \cdot M\right)}\right)}^{-1} \cdot 1\\ \end{array} \]
                                                                                                    6. Add Preprocessing

                                                                                                    Alternative 10: 51.7% accurate, 2.5× speedup?

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

                                                                                                      1. Initial program 64.3%

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

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

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

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

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

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

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

                                                                                                          if -2.00000000000000009e48 < m < -2.40000000000000014e-219

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

                                                                                                              \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
                                                                                                          5. Applied rewrites32.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-neg-revN/A

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

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

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

                                                                                                            \[\leadsto 1 \cdot e^{-\ell} \]
                                                                                                          10. Step-by-step derivation
                                                                                                            1. Applied rewrites36.1%

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

                                                                                                            if -2.40000000000000014e-219 < m < 8.0000000000000004e-22

                                                                                                            1. Initial program 80.3%

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

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

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

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

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

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

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

                                                                                                              Alternative 11: 48.3% accurate, 2.6× speedup?

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

                                                                                                                1. Initial program 59.3%

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

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

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

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

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

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

                                                                                                                    if -2.00000000000000009e48 < m < -2.09999999999999994e-218

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

                                                                                                                        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
                                                                                                                    5. Applied rewrites32.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-neg-revN/A

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

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

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

                                                                                                                      \[\leadsto 1 \cdot e^{-\ell} \]
                                                                                                                    10. Step-by-step derivation
                                                                                                                      1. Applied rewrites36.1%

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

                                                                                                                      if -2.09999999999999994e-218 < m

                                                                                                                      1. Initial program 74.9%

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

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

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

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

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

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

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

                                                                                                                        Alternative 12: 46.7% accurate, 2.6× speedup?

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

                                                                                                                          1. Initial program 70.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.f6426.2

                                                                                                                              \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
                                                                                                                          5. Applied rewrites26.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-neg-revN/A

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

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

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

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

                                                                                                                            if -1.70000000000000015e66 < l < 4.3000000000000001e-7

                                                                                                                            1. Initial program 68.3%

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

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

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

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

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

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

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

                                                                                                                                if 4.3000000000000001e-7 < l

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

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

                                                                                                                                  \[\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-neg-revN/A

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

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

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

                                                                                                                                  \[\leadsto 1 \cdot e^{-\ell} \]
                                                                                                                                10. Step-by-step derivation
                                                                                                                                  1. Applied rewrites95.0%

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

                                                                                                                                Alternative 13: 35.1% accurate, 3.3× speedup?

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

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

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

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

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

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

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

                                                                                                                                  \[\leadsto 1 \cdot e^{-\ell} \]
                                                                                                                                10. Step-by-step derivation
                                                                                                                                  1. Applied rewrites31.4%

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

                                                                                                                                  Reproduce

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