Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.4% → 96.5%
Time: 10.4s
Alternatives: 9
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 76.4% accurate, 1.0× speedup?

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

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

Alternative 1: 96.5% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\left(-M\right) \cdot M} \cdot 1\\
\mathbf{if}\;M \leq -1 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 3 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(M \cdot M, -0.5, 1\right) \cdot e^{\left|n - m\right| - \left({\left(\mathsf{fma}\left(0.5, n + m, -M\right)\right)}^{2} + \ell\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -9.9999999999999998e146 or 3e83 < M

    1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -9.9999999999999998e146 < M < 3e83

      1. Initial program 73.3%

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

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

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

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

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

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

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

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

      Alternative 2: 97.0% accurate, 1.1× speedup?

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

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

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

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

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

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

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

      Alternative 3: 89.0% accurate, 1.4× speedup?

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

        1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -9.9999999999999998e146 < M < 3e83

          1. Initial program 73.3%

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

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

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

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

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

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

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

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

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

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

            Alternative 4: 63.9% accurate, 1.5× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -85000:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\ \mathbf{elif}\;m \leq -8.5 \cdot 10^{-73}:\\ \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;m \leq -1.66 \cdot 10^{-183}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot \cos M\\ \end{array} \end{array} \]
            (FPCore (K m n M l)
             :precision binary64
             (if (<= m -85000.0)
               (* (exp (* -0.25 (* m m))) 1.0)
               (if (<= m -8.5e-73)
                 (* (exp (- l)) (fma (* M M) -0.5 1.0))
                 (if (<= m -1.66e-183)
                   (* (exp (* (- M) M)) 1.0)
                   (* (exp (* (* n n) -0.25)) (cos M))))))
            double code(double K, double m, double n, double M, double l) {
            	double tmp;
            	if (m <= -85000.0) {
            		tmp = exp((-0.25 * (m * m))) * 1.0;
            	} else if (m <= -8.5e-73) {
            		tmp = exp(-l) * fma((M * M), -0.5, 1.0);
            	} else if (m <= -1.66e-183) {
            		tmp = exp((-M * M)) * 1.0;
            	} else {
            		tmp = exp(((n * n) * -0.25)) * cos(M);
            	}
            	return tmp;
            }
            
            function code(K, m, n, M, l)
            	tmp = 0.0
            	if (m <= -85000.0)
            		tmp = Float64(exp(Float64(-0.25 * Float64(m * m))) * 1.0);
            	elseif (m <= -8.5e-73)
            		tmp = Float64(exp(Float64(-l)) * fma(Float64(M * M), -0.5, 1.0));
            	elseif (m <= -1.66e-183)
            		tmp = Float64(exp(Float64(Float64(-M) * M)) * 1.0);
            	else
            		tmp = Float64(exp(Float64(Float64(n * n) * -0.25)) * cos(M));
            	end
            	return tmp
            end
            
            code[K_, m_, n_, M_, l_] := If[LessEqual[m, -85000.0], N[(N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision], If[LessEqual[m, -8.5e-73], N[(N[Exp[(-l)], $MachinePrecision] * N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[m, -1.66e-183], N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision], N[(N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision] * N[Cos[M], $MachinePrecision]), $MachinePrecision]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;m \leq -85000:\\
            \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\
            
            \mathbf{elif}\;m \leq -8.5 \cdot 10^{-73}:\\
            \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
            
            \mathbf{elif}\;m \leq -1.66 \cdot 10^{-183}:\\
            \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\
            
            \mathbf{else}:\\
            \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot \cos M\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 4 regimes
            2. if m < -85000

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if -85000 < m < -8.4999999999999996e-73

                1. Initial program 74.7%

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

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

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

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

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

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

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

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

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

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

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

                  if -8.4999999999999996e-73 < m < -1.66e-183

                  1. Initial program 82.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.f6430.9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if -1.66e-183 < m

                    1. Initial program 78.0%

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -85000:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\ \mathbf{elif}\;m \leq -8.5 \cdot 10^{-73}:\\ \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;m \leq -1.66 \cdot 10^{-183}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot \cos M\\ \end{array} \]
                  13. Add Preprocessing

                  Alternative 5: 74.4% accurate, 2.6× speedup?

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

                    1. Initial program 71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      if -3.6e14 < m < -7.1e-233 or 1e-282 < m < 4.8000000000000002e-11

                      1. Initial program 76.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 l around inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        if -7.1e-233 < m < 1e-282

                        1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

                          \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -3.6 \cdot 10^{+14}:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\ \mathbf{elif}\;m \leq -7.1 \cdot 10^{-233}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{elif}\;m \leq 10^{-282}:\\ \;\;\;\;e^{-\ell} \cdot 1\\ \mathbf{elif}\;m \leq 4.8 \cdot 10^{-11}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\ \end{array} \]
                        13. Add Preprocessing

                        Alternative 6: 63.9% accurate, 2.7× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -85000:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\ \mathbf{elif}\;m \leq -8.5 \cdot 10^{-73}:\\ \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;m \leq -1 \cdot 10^{-185}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot 1\\ \end{array} \end{array} \]
                        (FPCore (K m n M l)
                         :precision binary64
                         (if (<= m -85000.0)
                           (* (exp (* -0.25 (* m m))) 1.0)
                           (if (<= m -8.5e-73)
                             (* (exp (- l)) (fma (* M M) -0.5 1.0))
                             (if (<= m -1e-185)
                               (* (exp (* (- M) M)) 1.0)
                               (* (exp (* (* n n) -0.25)) 1.0)))))
                        double code(double K, double m, double n, double M, double l) {
                        	double tmp;
                        	if (m <= -85000.0) {
                        		tmp = exp((-0.25 * (m * m))) * 1.0;
                        	} else if (m <= -8.5e-73) {
                        		tmp = exp(-l) * fma((M * M), -0.5, 1.0);
                        	} else if (m <= -1e-185) {
                        		tmp = exp((-M * M)) * 1.0;
                        	} else {
                        		tmp = exp(((n * n) * -0.25)) * 1.0;
                        	}
                        	return tmp;
                        }
                        
                        function code(K, m, n, M, l)
                        	tmp = 0.0
                        	if (m <= -85000.0)
                        		tmp = Float64(exp(Float64(-0.25 * Float64(m * m))) * 1.0);
                        	elseif (m <= -8.5e-73)
                        		tmp = Float64(exp(Float64(-l)) * fma(Float64(M * M), -0.5, 1.0));
                        	elseif (m <= -1e-185)
                        		tmp = Float64(exp(Float64(Float64(-M) * M)) * 1.0);
                        	else
                        		tmp = Float64(exp(Float64(Float64(n * n) * -0.25)) * 1.0);
                        	end
                        	return tmp
                        end
                        
                        code[K_, m_, n_, M_, l_] := If[LessEqual[m, -85000.0], N[(N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision], If[LessEqual[m, -8.5e-73], N[(N[Exp[(-l)], $MachinePrecision] * N[(N[(M * M), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[m, -1e-185], N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision], N[(N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]]]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;m \leq -85000:\\
                        \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\
                        
                        \mathbf{elif}\;m \leq -8.5 \cdot 10^{-73}:\\
                        \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\
                        
                        \mathbf{elif}\;m \leq -1 \cdot 10^{-185}:\\
                        \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot 1\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 4 regimes
                        2. if m < -85000

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            if -85000 < m < -8.4999999999999996e-73

                            1. Initial program 74.7%

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

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

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

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

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

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

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

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

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

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

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

                              if -8.4999999999999996e-73 < m < -9.9999999999999999e-186

                              1. Initial program 82.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.f6430.9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                if -9.9999999999999999e-186 < m

                                1. Initial program 78.0%

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

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

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

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

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

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

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

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

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

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

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

                                  \[\leadsto 1 \cdot e^{\left(n \cdot n\right) \cdot \frac{-1}{4}} \]
                                10. Step-by-step derivation
                                  1. Applied rewrites55.3%

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

                                  \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -85000:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\ \mathbf{elif}\;m \leq -8.5 \cdot 10^{-73}:\\ \;\;\;\;e^{-\ell} \cdot \mathsf{fma}\left(M \cdot M, -0.5, 1\right)\\ \mathbf{elif}\;m \leq -1 \cdot 10^{-185}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot 1\\ \end{array} \]
                                13. Add Preprocessing

                                Alternative 7: 64.7% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if -3.6e14 < m < -9.9999999999999999e-186

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                      if -9.9999999999999999e-186 < m

                                      1. Initial program 78.0%

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto 1 \cdot e^{\left(n \cdot n\right) \cdot \frac{-1}{4}} \]
                                      10. Step-by-step derivation
                                        1. Applied rewrites55.3%

                                          \[\leadsto 1 \cdot e^{\left(n \cdot n\right) \cdot -0.25} \]
                                      11. Recombined 3 regimes into one program.
                                      12. Final simplification62.3%

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -3.6 \cdot 10^{+14}:\\ \;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot 1\\ \mathbf{elif}\;m \leq -1 \cdot 10^{-185}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot 1\\ \end{array} \]
                                      13. Add Preprocessing

                                      Alternative 8: 69.0% accurate, 2.9× speedup?

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

                                        1. Initial program 74.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                          if -27 < M < 2.00000000000000014e-17

                                          1. Initial program 77.9%

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

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

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

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

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

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

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

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

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

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

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

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

                                          Alternative 9: 34.9% accurate, 3.3× speedup?

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

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

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

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

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

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

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

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

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

                                              \[\leadsto 1 \cdot e^{-\ell} \]
                                            2. Final simplification35.9%

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

                                            Reproduce

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