Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.0% → 96.7%
Time: 13.8s
Alternatives: 11
Speedup: 2.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 76.0% 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.7% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5, n + m, -M\right)\\
\cos M \cdot e^{\left|n - m\right| - \mathsf{fma}\left(t\_0, t\_0, \ell\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 77.6%

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

    \[\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. lower-*.f64N/A

      \[\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)}} \]
    2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 95.3% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-M \cdot M}\\ \mathbf{if}\;M \leq -1.65 \cdot 10^{+25}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 31.5:\\ \;\;\;\;e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \left(n + m\right), \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- (* M M)))))
   (if (<= M -1.65e+25)
     t_0
     (if (<= M 31.5)
       (exp (- (fabs (- n m)) (fma 0.25 (* (+ n m) (+ n m)) l)))
       t_0))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(-(M * M));
	double tmp;
	if (M <= -1.65e+25) {
		tmp = t_0;
	} else if (M <= 31.5) {
		tmp = exp((fabs((n - m)) - fma(0.25, ((n + m) * (n + m)), l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = exp(Float64(-Float64(M * M)))
	tmp = 0.0
	if (M <= -1.65e+25)
		tmp = t_0;
	elseif (M <= 31.5)
		tmp = exp(Float64(abs(Float64(n - m)) - fma(0.25, Float64(Float64(n + m) * Float64(n + m)), l)));
	else
		tmp = t_0;
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-N[(M * M), $MachinePrecision])], $MachinePrecision]}, If[LessEqual[M, -1.65e+25], t$95$0, If[LessEqual[M, 31.5], N[Exp[N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - N[(0.25 * N[(N[(n + m), $MachinePrecision] * N[(n + m), $MachinePrecision]), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-M \cdot M}\\
\mathbf{if}\;M \leq -1.65 \cdot 10^{+25}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 31.5:\\
\;\;\;\;e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \left(n + m\right), \ell\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -1.6500000000000001e25 or 31.5 < M

    1. Initial program 79.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. lower-*.f64N/A

        \[\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)}} \]
      2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -1.6500000000000001e25 < M < 31.5

      1. Initial program 75.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. lower-*.f64N/A

          \[\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)}} \]
        2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto e^{\left|m - n\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
        12. unpow2N/A

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

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

          \[\leadsto e^{\left|m - n\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right)} \cdot \left(m + n\right), \ell\right)} \]
        15. lower-+.f6493.3

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

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

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

    Alternative 3: 96.3% accurate, 2.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(0.5, n + m, -M\right)\\ e^{\left|n - m\right| - \mathsf{fma}\left(t\_0, t\_0, \ell\right)} \end{array} \end{array} \]
    (FPCore (K m n M l)
     :precision binary64
     (let* ((t_0 (fma 0.5 (+ n m) (- M))))
       (exp (- (fabs (- n m)) (fma t_0 t_0 l)))))
    double code(double K, double m, double n, double M, double l) {
    	double t_0 = fma(0.5, (n + m), -M);
    	return exp((fabs((n - m)) - fma(t_0, t_0, l)));
    }
    
    function code(K, m, n, M, l)
    	t_0 = fma(0.5, Float64(n + m), Float64(-M))
    	return exp(Float64(abs(Float64(n - m)) - fma(t_0, t_0, l)))
    end
    
    code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(0.5 * N[(n + m), $MachinePrecision] + (-M)), $MachinePrecision]}, N[Exp[N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - N[(t$95$0 * t$95$0 + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \mathsf{fma}\left(0.5, n + m, -M\right)\\
    e^{\left|n - m\right| - \mathsf{fma}\left(t\_0, t\_0, \ell\right)}
    \end{array}
    \end{array}
    
    Derivation
    1. Initial program 77.6%

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

      \[\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. lower-*.f64N/A

        \[\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)}} \]
      2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 4: 62.8% accurate, 2.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -55:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq 1.02 \cdot 10^{-210}:\\ \;\;\;\;e^{-M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;e^{\mathsf{fma}\left(n, n \cdot -0.25, \left|n - m\right|\right)}\\ \end{array} \end{array} \]
      (FPCore (K m n M l)
       :precision binary64
       (if (<= m -55.0)
         (exp (* -0.25 (* m m)))
         (if (<= m 1.02e-210)
           (exp (- (* M M)))
           (exp (fma n (* n -0.25) (fabs (- n m)))))))
      double code(double K, double m, double n, double M, double l) {
      	double tmp;
      	if (m <= -55.0) {
      		tmp = exp((-0.25 * (m * m)));
      	} else if (m <= 1.02e-210) {
      		tmp = exp(-(M * M));
      	} else {
      		tmp = exp(fma(n, (n * -0.25), fabs((n - m))));
      	}
      	return tmp;
      }
      
      function code(K, m, n, M, l)
      	tmp = 0.0
      	if (m <= -55.0)
      		tmp = exp(Float64(-0.25 * Float64(m * m)));
      	elseif (m <= 1.02e-210)
      		tmp = exp(Float64(-Float64(M * M)));
      	else
      		tmp = exp(fma(n, Float64(n * -0.25), abs(Float64(n - m))));
      	end
      	return tmp
      end
      
      code[K_, m_, n_, M_, l_] := If[LessEqual[m, -55.0], N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, 1.02e-210], N[Exp[(-N[(M * M), $MachinePrecision])], $MachinePrecision], N[Exp[N[(n * N[(n * -0.25), $MachinePrecision] + N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;m \leq -55:\\
      \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\
      
      \mathbf{elif}\;m \leq 1.02 \cdot 10^{-210}:\\
      \;\;\;\;e^{-M \cdot M}\\
      
      \mathbf{else}:\\
      \;\;\;\;e^{\mathsf{fma}\left(n, n \cdot -0.25, \left|n - m\right|\right)}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if m < -55

        1. Initial program 75.8%

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

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

            \[\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)}} \]
          2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -55 < m < 1.02000000000000002e-210

          1. Initial program 80.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. lower-*.f64N/A

              \[\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)}} \]
            2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 1.02000000000000002e-210 < m

            1. Initial program 75.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. lower-*.f64N/A

                \[\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)}} \]
              2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto 1 \cdot e^{\left|n - m\right| - \color{blue}{\frac{1}{4} \cdot {n}^{2}}} \]
              3. Step-by-step derivation
                1. lower-*.f64N/A

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

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

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

                \[\leadsto 1 \cdot e^{\left|n - m\right| - \color{blue}{0.25 \cdot \left(n \cdot n\right)}} \]
              5. Step-by-step derivation
                1. lift--.f64N/A

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

                  \[\leadsto 1 \cdot e^{\color{blue}{\left|n - m\right|} - \frac{1}{4} \cdot \left(n \cdot n\right)} \]
                3. lift-*.f64N/A

                  \[\leadsto 1 \cdot e^{\left|n - m\right| - \frac{1}{4} \cdot \color{blue}{\left(n \cdot n\right)}} \]
                4. lift-*.f64N/A

                  \[\leadsto 1 \cdot e^{\left|n - m\right| - \color{blue}{\frac{1}{4} \cdot \left(n \cdot n\right)}} \]
                5. lift--.f64N/A

                  \[\leadsto 1 \cdot e^{\color{blue}{\left|n - m\right| - \frac{1}{4} \cdot \left(n \cdot n\right)}} \]
                6. lift-exp.f64N/A

                  \[\leadsto 1 \cdot \color{blue}{e^{\left|n - m\right| - \frac{1}{4} \cdot \left(n \cdot n\right)}} \]
                7. *-lft-identity50.7

                  \[\leadsto \color{blue}{e^{\left|n - m\right| - 0.25 \cdot \left(n \cdot n\right)}} \]
                8. lift--.f64N/A

                  \[\leadsto e^{\color{blue}{\left|n - m\right| - \frac{1}{4} \cdot \left(n \cdot n\right)}} \]
                9. sub-negN/A

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

                  \[\leadsto e^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{4} \cdot \left(n \cdot n\right)\right)\right) + \left|n - m\right|}} \]
                11. lift-*.f64N/A

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

                  \[\leadsto e^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot \left(n \cdot n\right)} + \left|n - m\right|} \]
                13. metadata-evalN/A

                  \[\leadsto e^{\color{blue}{\frac{-1}{4}} \cdot \left(n \cdot n\right) + \left|n - m\right|} \]
                14. lift-*.f64N/A

                  \[\leadsto e^{\frac{-1}{4} \cdot \color{blue}{\left(n \cdot n\right)} + \left|n - m\right|} \]
                15. associate-*r*N/A

                  \[\leadsto e^{\color{blue}{\left(\frac{-1}{4} \cdot n\right) \cdot n} + \left|n - m\right|} \]
                16. *-commutativeN/A

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

                  \[\leadsto e^{\color{blue}{\mathsf{fma}\left(n, \frac{-1}{4} \cdot n, \left|n - m\right|\right)}} \]
                18. *-commutativeN/A

                  \[\leadsto e^{\mathsf{fma}\left(n, \color{blue}{n \cdot \frac{-1}{4}}, \left|n - m\right|\right)} \]
                19. lower-*.f6450.7

                  \[\leadsto e^{\mathsf{fma}\left(n, \color{blue}{n \cdot -0.25}, \left|n - m\right|\right)} \]
              6. Applied rewrites50.7%

                \[\leadsto \color{blue}{e^{\mathsf{fma}\left(n, n \cdot -0.25, \left|n - m\right|\right)}} \]
            8. Recombined 3 regimes into one program.
            9. Final simplification60.6%

              \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -55:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq 1.02 \cdot 10^{-210}:\\ \;\;\;\;e^{-M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;e^{\mathsf{fma}\left(n, n \cdot -0.25, \left|n - m\right|\right)}\\ \end{array} \]
            10. Add Preprocessing

            Alternative 5: 65.7% accurate, 2.9× speedup?

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

              1. Initial program 75.8%

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

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

                  \[\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)}} \]
                2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if -55 < m < 1.02000000000000002e-210

                1. Initial program 80.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. lower-*.f64N/A

                    \[\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)}} \]
                  2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if 1.02000000000000002e-210 < m

                  1. Initial program 75.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. lower-*.f64N/A

                      \[\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)}} \]
                    2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot \left(n \cdot n\right)}} \]
                    5. Taylor expanded in n around inf

                      \[\leadsto \color{blue}{e^{\frac{-1}{4} \cdot {n}^{2}}} \]
                    6. Step-by-step derivation
                      1. lower-exp.f64N/A

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

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

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

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

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

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

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

                  Alternative 6: 77.0% accurate, 2.9× speedup?

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

                    1. Initial program 69.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. lower-*.f64N/A

                        \[\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)}} \]
                      2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot \left(n \cdot n\right)}} \]
                      5. Taylor expanded in n around inf

                        \[\leadsto \color{blue}{e^{\frac{-1}{4} \cdot {n}^{2}}} \]
                      6. Step-by-step derivation
                        1. lower-exp.f64N/A

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

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

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

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

                          \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
                      7. Applied rewrites95.8%

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

                      if -54 < n < 55

                      1. Initial program 87.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. lower-*.f64N/A

                          \[\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)}} \]
                        2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      Alternative 7: 70.1% accurate, 2.9× speedup?

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

                        1. Initial program 69.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. lower-*.f64N/A

                            \[\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)}} \]
                          2. cos-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto 1 \cdot e^{\color{blue}{-0.25 \cdot \left(n \cdot n\right)}} \]
                          5. Taylor expanded in n around inf

                            \[\leadsto \color{blue}{e^{\frac{-1}{4} \cdot {n}^{2}}} \]
                          6. Step-by-step derivation
                            1. lower-exp.f64N/A

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

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

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

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

                              \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
                          7. Applied rewrites95.8%

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

                          if -53 < n < 52

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

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

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

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

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

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

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

                            \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right)\right)} \cdot e^{-\ell} \]
                          9. Taylor expanded in n around 0

                            \[\leadsto \color{blue}{e^{\mathsf{neg}\left(\ell\right)}} \]
                          10. Step-by-step derivation
                            1. neg-mul-1N/A

                              \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
                            2. lower-exp.f64N/A

                              \[\leadsto \color{blue}{e^{-1 \cdot \ell}} \]
                            3. neg-mul-1N/A

                              \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                            4. lower-neg.f6435.3

                              \[\leadsto e^{\color{blue}{-\ell}} \]
                          11. Applied rewrites35.3%

                            \[\leadsto \color{blue}{e^{-\ell}} \]
                        8. Recombined 2 regimes into one program.
                        9. Final simplification68.9%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -53:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \mathbf{elif}\;n \leq 52:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]
                        10. Add Preprocessing

                        Alternative 8: 36.0% accurate, 3.5× speedup?

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

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

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

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

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

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

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

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

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

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

                          \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right)\right)} \cdot e^{-\ell} \]
                        9. Taylor expanded in n around 0

                          \[\leadsto \color{blue}{e^{\mathsf{neg}\left(\ell\right)}} \]
                        10. Step-by-step derivation
                          1. neg-mul-1N/A

                            \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
                          2. lower-exp.f64N/A

                            \[\leadsto \color{blue}{e^{-1 \cdot \ell}} \]
                          3. neg-mul-1N/A

                            \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
                          4. lower-neg.f6430.5

                            \[\leadsto e^{\color{blue}{-\ell}} \]
                        11. Applied rewrites30.5%

                          \[\leadsto \color{blue}{e^{-\ell}} \]
                        12. Add Preprocessing

                        Alternative 9: 9.3% accurate, 8.0× speedup?

                        \[\begin{array}{l} \\ \mathsf{fma}\left(K, K \cdot \left(\left(n \cdot n\right) \cdot -0.125\right), 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right) \end{array} \]
                        (FPCore (K m n M l)
                         :precision binary64
                         (*
                          (fma K (* K (* (* n n) -0.125)) 1.0)
                          (fma l (fma l (fma l -0.16666666666666666 0.5) -1.0) 1.0)))
                        double code(double K, double m, double n, double M, double l) {
                        	return fma(K, (K * ((n * n) * -0.125)), 1.0) * fma(l, fma(l, fma(l, -0.16666666666666666, 0.5), -1.0), 1.0);
                        }
                        
                        function code(K, m, n, M, l)
                        	return Float64(fma(K, Float64(K * Float64(Float64(n * n) * -0.125)), 1.0) * fma(l, fma(l, fma(l, -0.16666666666666666, 0.5), -1.0), 1.0))
                        end
                        
                        code[K_, m_, n_, M_, l_] := N[(N[(K * N[(K * N[(N[(n * n), $MachinePrecision] * -0.125), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[(l * N[(l * N[(l * -0.16666666666666666 + 0.5), $MachinePrecision] + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
                        
                        \begin{array}{l}
                        
                        \\
                        \mathsf{fma}\left(K, K \cdot \left(\left(n \cdot n\right) \cdot -0.125\right), 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right)
                        \end{array}
                        
                        Derivation
                        1. Initial program 77.6%

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

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

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

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

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

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

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

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

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

                          \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right)\right)} \cdot e^{-\ell} \]
                        9. Taylor expanded in l around 0

                          \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \color{blue}{\left(1 + \ell \cdot \left(\ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) - 1\right)\right)} \]
                        10. Step-by-step derivation
                          1. +-commutativeN/A

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

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) - 1, 1\right)} \]
                          3. sub-negN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) + \left(\mathsf{neg}\left(1\right)\right)}, 1\right) \]
                          4. metadata-evalN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) + \color{blue}{-1}, 1\right) \]
                          5. lower-fma.f64N/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{2} + \frac{-1}{6} \cdot \ell, -1\right)}, 1\right) \]
                          6. +-commutativeN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\frac{-1}{6} \cdot \ell + \frac{1}{2}}, -1\right), 1\right) \]
                          7. *-commutativeN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{-1}{6}} + \frac{1}{2}, -1\right), 1\right) \]
                          8. lower-fma.f649.6

                            \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right)}, -1\right), 1\right) \]
                        11. Applied rewrites9.6%

                          \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot \color{blue}{\mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right)} \]
                        12. Taylor expanded in n around 0

                          \[\leadsto \color{blue}{\left(1 + \frac{-1}{8} \cdot \left({K}^{2} \cdot {n}^{2}\right)\right)} \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                        13. Step-by-step derivation
                          1. associate-*r*N/A

                            \[\leadsto \left(1 + \color{blue}{\left(\frac{-1}{8} \cdot {K}^{2}\right) \cdot {n}^{2}}\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          2. +-commutativeN/A

                            \[\leadsto \color{blue}{\left(\left(\frac{-1}{8} \cdot {K}^{2}\right) \cdot {n}^{2} + 1\right)} \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          3. *-commutativeN/A

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

                            \[\leadsto \left(\color{blue}{{K}^{2} \cdot \left(\frac{-1}{8} \cdot {n}^{2}\right)} + 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          5. unpow2N/A

                            \[\leadsto \left(\color{blue}{\left(K \cdot K\right)} \cdot \left(\frac{-1}{8} \cdot {n}^{2}\right) + 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          6. associate-*l*N/A

                            \[\leadsto \left(\color{blue}{K \cdot \left(K \cdot \left(\frac{-1}{8} \cdot {n}^{2}\right)\right)} + 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          7. lower-fma.f64N/A

                            \[\leadsto \color{blue}{\mathsf{fma}\left(K, K \cdot \left(\frac{-1}{8} \cdot {n}^{2}\right), 1\right)} \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          8. lower-*.f64N/A

                            \[\leadsto \mathsf{fma}\left(K, \color{blue}{K \cdot \left(\frac{-1}{8} \cdot {n}^{2}\right)}, 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          9. lower-*.f64N/A

                            \[\leadsto \mathsf{fma}\left(K, K \cdot \color{blue}{\left(\frac{-1}{8} \cdot {n}^{2}\right)}, 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          10. unpow2N/A

                            \[\leadsto \mathsf{fma}\left(K, K \cdot \left(\frac{-1}{8} \cdot \color{blue}{\left(n \cdot n\right)}\right), 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \frac{-1}{6}, \frac{1}{2}\right), -1\right), 1\right) \]
                          11. lower-*.f648.3

                            \[\leadsto \mathsf{fma}\left(K, K \cdot \left(-0.125 \cdot \color{blue}{\left(n \cdot n\right)}\right), 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right) \]
                        14. Applied rewrites8.3%

                          \[\leadsto \color{blue}{\mathsf{fma}\left(K, K \cdot \left(-0.125 \cdot \left(n \cdot n\right)\right), 1\right)} \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right) \]
                        15. Final simplification8.3%

                          \[\leadsto \mathsf{fma}\left(K, K \cdot \left(\left(n \cdot n\right) \cdot -0.125\right), 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right) \]
                        16. Add Preprocessing

                        Alternative 10: 9.8% accurate, 18.9× speedup?

                        \[\begin{array}{l} \\ \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right) \end{array} \]
                        (FPCore (K m n M l)
                         :precision binary64
                         (fma l (fma l (fma l -0.16666666666666666 0.5) -1.0) 1.0))
                        double code(double K, double m, double n, double M, double l) {
                        	return fma(l, fma(l, fma(l, -0.16666666666666666, 0.5), -1.0), 1.0);
                        }
                        
                        function code(K, m, n, M, l)
                        	return fma(l, fma(l, fma(l, -0.16666666666666666, 0.5), -1.0), 1.0)
                        end
                        
                        code[K_, m_, n_, M_, l_] := N[(l * N[(l * N[(l * -0.16666666666666666 + 0.5), $MachinePrecision] + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]
                        
                        \begin{array}{l}
                        
                        \\
                        \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right)
                        \end{array}
                        
                        Derivation
                        1. Initial program 77.6%

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

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

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

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

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

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

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

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

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

                          \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right)\right)} \cdot e^{-\ell} \]
                        9. Taylor expanded in l around 0

                          \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \color{blue}{\left(1 + \ell \cdot \left(\ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) - 1\right)\right)} \]
                        10. Step-by-step derivation
                          1. +-commutativeN/A

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

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) - 1, 1\right)} \]
                          3. sub-negN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) + \left(\mathsf{neg}\left(1\right)\right)}, 1\right) \]
                          4. metadata-evalN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) + \color{blue}{-1}, 1\right) \]
                          5. lower-fma.f64N/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{2} + \frac{-1}{6} \cdot \ell, -1\right)}, 1\right) \]
                          6. +-commutativeN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\frac{-1}{6} \cdot \ell + \frac{1}{2}}, -1\right), 1\right) \]
                          7. *-commutativeN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{-1}{6}} + \frac{1}{2}, -1\right), 1\right) \]
                          8. lower-fma.f649.6

                            \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right)}, -1\right), 1\right) \]
                        11. Applied rewrites9.6%

                          \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot \color{blue}{\mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right)} \]
                        12. Taylor expanded in n around 0

                          \[\leadsto \color{blue}{1 + \ell \cdot \left(\ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) - 1\right)} \]
                        13. Step-by-step derivation
                          1. +-commutativeN/A

                            \[\leadsto \color{blue}{\ell \cdot \left(\ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) - 1\right) + 1} \]
                          2. lower-fma.f64N/A

                            \[\leadsto \color{blue}{\mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) - 1, 1\right)} \]
                          3. sub-negN/A

                            \[\leadsto \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) + \left(\mathsf{neg}\left(1\right)\right)}, 1\right) \]
                          4. metadata-evalN/A

                            \[\leadsto \mathsf{fma}\left(\ell, \ell \cdot \left(\frac{1}{2} + \frac{-1}{6} \cdot \ell\right) + \color{blue}{-1}, 1\right) \]
                          5. lower-fma.f64N/A

                            \[\leadsto \mathsf{fma}\left(\ell, \color{blue}{\mathsf{fma}\left(\ell, \frac{1}{2} + \frac{-1}{6} \cdot \ell, -1\right)}, 1\right) \]
                          6. +-commutativeN/A

                            \[\leadsto \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\frac{-1}{6} \cdot \ell + \frac{1}{2}}, -1\right), 1\right) \]
                          7. *-commutativeN/A

                            \[\leadsto \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\ell \cdot \frac{-1}{6}} + \frac{1}{2}, -1\right), 1\right) \]
                          8. lower-fma.f648.7

                            \[\leadsto \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right)}, -1\right), 1\right) \]
                        14. Applied rewrites8.7%

                          \[\leadsto \color{blue}{\mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, -0.16666666666666666, 0.5\right), -1\right), 1\right)} \]
                        15. Add Preprocessing

                        Alternative 11: 6.7% accurate, 359.0× speedup?

                        \[\begin{array}{l} \\ 1 \end{array} \]
                        (FPCore (K m n M l) :precision binary64 1.0)
                        double code(double K, double m, double n, double M, double l) {
                        	return 1.0;
                        }
                        
                        real(8) function code(k, m, n, m_1, l)
                            real(8), intent (in) :: k
                            real(8), intent (in) :: m
                            real(8), intent (in) :: n
                            real(8), intent (in) :: m_1
                            real(8), intent (in) :: l
                            code = 1.0d0
                        end function
                        
                        public static double code(double K, double m, double n, double M, double l) {
                        	return 1.0;
                        }
                        
                        def code(K, m, n, M, l):
                        	return 1.0
                        
                        function code(K, m, n, M, l)
                        	return 1.0
                        end
                        
                        function tmp = code(K, m, n, M, l)
                        	tmp = 1.0;
                        end
                        
                        code[K_, m_, n_, M_, l_] := 1.0
                        
                        \begin{array}{l}
                        
                        \\
                        1
                        \end{array}
                        
                        Derivation
                        1. Initial program 77.6%

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto \cos \left(\color{blue}{\frac{1}{2} \cdot \left(K \cdot n\right)} - M\right) \]
                          4. *-commutativeN/A

                            \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
                          5. lower-*.f645.5

                            \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
                        8. Applied rewrites5.5%

                          \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(n \cdot K\right) - M\right)} \]
                        9. Taylor expanded in n around 0

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

                            \[\leadsto \color{blue}{\cos M} \]
                          2. lower-cos.f645.8

                            \[\leadsto \color{blue}{\cos M} \]
                        11. Applied rewrites5.8%

                          \[\leadsto \color{blue}{\cos M} \]
                        12. Taylor expanded in M around 0

                          \[\leadsto \color{blue}{1} \]
                        13. Step-by-step derivation
                          1. Applied rewrites5.8%

                            \[\leadsto \color{blue}{1} \]
                          2. Add Preprocessing

                          Reproduce

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