Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 96.6%
Time: 10.7s
Alternatives: 9
Speedup: 1.1×

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

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

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

Alternative 1: 96.6% accurate, 1.1× speedup?

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

\\
e^{\left(\left|n - m\right| - \ell\right) - {\left(\frac{n + m}{2} - M\right)}^{2}} \cdot \cos M
\end{array}
Derivation
  1. Initial program 77.7%

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

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

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

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

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

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

Alternative 2: 86.8% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(n + m, 0.5, -M\right)\\
t_1 := \left|n - m\right|\\
t_2 := e^{-\ell}\\
t_3 := \cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right)\\
t_4 := t\_3 \cdot e^{\left(t\_1 - \ell\right) - {\left(\frac{n + m}{2} - M\right)}^{2}}\\
\mathbf{if}\;t\_4 \leq -0.1:\\
\;\;\;\;\cos \left(\frac{1}{\frac{\frac{\mathsf{fma}\left(-2, \frac{m}{n}, 2\right)}{n}}{K}} - M\right) \cdot t\_2\\

\mathbf{elif}\;t\_4 \leq 0:\\
\;\;\;\;\left(\left(-\ell\right) \cdot e^{t\_1 - t\_0 \cdot t\_0}\right) \cdot t\_3\\

\mathbf{elif}\;t\_4 \leq \infty:\\
\;\;\;\;t\_2 \cdot \cos M\\

\mathbf{else}:\\
\;\;\;\;e^{-0.25 \cdot \left(m \cdot m\right)} \cdot \cos M\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < -0.10000000000000001

    1. Initial program 34.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. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.10000000000000001 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < -0.0

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -0.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < +inf.0

      1. Initial program 78.1%

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

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

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

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

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

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

          \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        2. lower-cos.f6479.9

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

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

      if +inf.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

      1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(m \cdot m\right) \cdot -0.25} \]
      8. Applied rewrites61.7%

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

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

    Alternative 3: 85.8% accurate, 0.4× speedup?

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

      1. Initial program 97.5%

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

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

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

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

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

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

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

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

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

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

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

      if -0.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < +inf.0

      1. Initial program 78.1%

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

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

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

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

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

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

          \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        2. lower-cos.f6479.9

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

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

      if +inf.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

      1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\cos M} \cdot e^{\left(m \cdot m\right) \cdot -0.25} \]
      8. Applied rewrites61.7%

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

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

    Alternative 4: 65.8% accurate, 1.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -6600:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.25 \cdot 10^{-226}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\ \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 -6600.0)
       (* 1.0 (exp (* -0.25 (* m m))))
       (if (<= m -1.25e-226)
         (* (exp (* (- M) M)) (cos (- (/ K (/ 2.0 m)) M)))
         (* (exp (* (* n n) -0.25)) (cos M)))))
    double code(double K, double m, double n, double M, double l) {
    	double tmp;
    	if (m <= -6600.0) {
    		tmp = 1.0 * exp((-0.25 * (m * m)));
    	} else if (m <= -1.25e-226) {
    		tmp = exp((-M * M)) * cos(((K / (2.0 / m)) - M));
    	} else {
    		tmp = exp(((n * n) * -0.25)) * cos(M);
    	}
    	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 <= (-6600.0d0)) then
            tmp = 1.0d0 * exp(((-0.25d0) * (m * m)))
        else if (m <= (-1.25d-226)) then
            tmp = exp((-m_1 * m_1)) * cos(((k / (2.0d0 / m)) - m_1))
        else
            tmp = exp(((n * n) * (-0.25d0))) * cos(m_1)
        end if
        code = tmp
    end function
    
    public static double code(double K, double m, double n, double M, double l) {
    	double tmp;
    	if (m <= -6600.0) {
    		tmp = 1.0 * Math.exp((-0.25 * (m * m)));
    	} else if (m <= -1.25e-226) {
    		tmp = Math.exp((-M * M)) * Math.cos(((K / (2.0 / m)) - M));
    	} else {
    		tmp = Math.exp(((n * n) * -0.25)) * Math.cos(M);
    	}
    	return tmp;
    }
    
    def code(K, m, n, M, l):
    	tmp = 0
    	if m <= -6600.0:
    		tmp = 1.0 * math.exp((-0.25 * (m * m)))
    	elif m <= -1.25e-226:
    		tmp = math.exp((-M * M)) * math.cos(((K / (2.0 / m)) - M))
    	else:
    		tmp = math.exp(((n * n) * -0.25)) * math.cos(M)
    	return tmp
    
    function code(K, m, n, M, l)
    	tmp = 0.0
    	if (m <= -6600.0)
    		tmp = Float64(1.0 * exp(Float64(-0.25 * Float64(m * m))));
    	elseif (m <= -1.25e-226)
    		tmp = Float64(exp(Float64(Float64(-M) * M)) * cos(Float64(Float64(K / Float64(2.0 / m)) - M)));
    	else
    		tmp = Float64(exp(Float64(Float64(n * n) * -0.25)) * cos(M));
    	end
    	return tmp
    end
    
    function tmp_2 = code(K, m, n, M, l)
    	tmp = 0.0;
    	if (m <= -6600.0)
    		tmp = 1.0 * exp((-0.25 * (m * m)));
    	elseif (m <= -1.25e-226)
    		tmp = exp((-M * M)) * cos(((K / (2.0 / m)) - M));
    	else
    		tmp = exp(((n * n) * -0.25)) * cos(M);
    	end
    	tmp_2 = tmp;
    end
    
    code[K_, m_, n_, M_, l_] := If[LessEqual[m, -6600.0], N[(1.0 * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, -1.25e-226], N[(N[Exp[N[((-M) * M), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(K / N[(2.0 / m), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $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 -6600:\\
    \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\
    
    \mathbf{elif}\;m \leq -1.25 \cdot 10^{-226}:\\
    \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot \cos M\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if m < -6600

      1. Initial program 73.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -6600 < m < -1.2499999999999999e-226

        1. Initial program 80.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. Step-by-step derivation
          1. lift-/.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -1.2499999999999999e-226 < m

        1. Initial program 78.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -6600:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.25 \cdot 10^{-226}:\\ \;\;\;\;e^{\left(-M\right) \cdot M} \cdot \cos \left(\frac{K}{\frac{2}{m}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25} \cdot \cos M\\ \end{array} \]
      13. Add Preprocessing

      Alternative 5: 65.7% accurate, 1.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -6600:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.55 \cdot 10^{-223}:\\ \;\;\;\;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 -6600.0)
         (* 1.0 (exp (* -0.25 (* m m))))
         (if (<= m -1.55e-223)
           (* (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 <= -6600.0) {
      		tmp = 1.0 * exp((-0.25 * (m * m)));
      	} else if (m <= -1.55e-223) {
      		tmp = exp((-M * M)) * 1.0;
      	} else {
      		tmp = exp(((n * n) * -0.25)) * cos(M);
      	}
      	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 <= (-6600.0d0)) then
              tmp = 1.0d0 * exp(((-0.25d0) * (m * m)))
          else if (m <= (-1.55d-223)) then
              tmp = exp((-m_1 * m_1)) * 1.0d0
          else
              tmp = exp(((n * n) * (-0.25d0))) * cos(m_1)
          end if
          code = tmp
      end function
      
      public static double code(double K, double m, double n, double M, double l) {
      	double tmp;
      	if (m <= -6600.0) {
      		tmp = 1.0 * Math.exp((-0.25 * (m * m)));
      	} else if (m <= -1.55e-223) {
      		tmp = Math.exp((-M * M)) * 1.0;
      	} else {
      		tmp = Math.exp(((n * n) * -0.25)) * Math.cos(M);
      	}
      	return tmp;
      }
      
      def code(K, m, n, M, l):
      	tmp = 0
      	if m <= -6600.0:
      		tmp = 1.0 * math.exp((-0.25 * (m * m)))
      	elif m <= -1.55e-223:
      		tmp = math.exp((-M * M)) * 1.0
      	else:
      		tmp = math.exp(((n * n) * -0.25)) * math.cos(M)
      	return tmp
      
      function code(K, m, n, M, l)
      	tmp = 0.0
      	if (m <= -6600.0)
      		tmp = Float64(1.0 * exp(Float64(-0.25 * Float64(m * m))));
      	elseif (m <= -1.55e-223)
      		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
      
      function tmp_2 = code(K, m, n, M, l)
      	tmp = 0.0;
      	if (m <= -6600.0)
      		tmp = 1.0 * exp((-0.25 * (m * m)));
      	elseif (m <= -1.55e-223)
      		tmp = exp((-M * M)) * 1.0;
      	else
      		tmp = exp(((n * n) * -0.25)) * cos(M);
      	end
      	tmp_2 = tmp;
      end
      
      code[K_, m_, n_, M_, l_] := If[LessEqual[m, -6600.0], N[(1.0 * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, -1.55e-223], 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 -6600:\\
      \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\
      
      \mathbf{elif}\;m \leq -1.55 \cdot 10^{-223}:\\
      \;\;\;\;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 3 regimes
      2. if m < -6600

        1. Initial program 73.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

          if -6600 < m < -1.55000000000000009e-223

          1. Initial program 82.7%

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

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

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

              \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
          5. Applied rewrites35.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^{\mathsf{neg}\left(\ell\right)} \]
          7. Step-by-step derivation
            1. cos-negN/A

              \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
            2. lower-cos.f6443.7

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

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

            \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
          10. Step-by-step derivation
            1. Applied rewrites43.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.f6466.4

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

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

            if -1.55000000000000009e-223 < m

            1. Initial program 77.6%

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -6600:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.55 \cdot 10^{-223}:\\ \;\;\;\;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 6: 73.6% accurate, 2.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{if}\;M \leq -0.08:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 3.7 \cdot 10^{-268}:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \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 -0.08)
               t_0
               (if (<= M 3.7e-268)
                 (* 1.0 (exp (* -0.25 (* m m))))
                 (if (<= M 27.0) (* 1.0 (exp (- 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 <= -0.08) {
          		tmp = t_0;
          	} else if (M <= 3.7e-268) {
          		tmp = 1.0 * exp((-0.25 * (m * m)));
          	} else if (M <= 27.0) {
          		tmp = 1.0 * exp(-l);
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          real(8) function code(k, m, n, m_1, l)
              real(8), intent (in) :: k
              real(8), intent (in) :: m
              real(8), intent (in) :: n
              real(8), intent (in) :: m_1
              real(8), intent (in) :: l
              real(8) :: t_0
              real(8) :: tmp
              t_0 = exp((-m_1 * m_1)) * 1.0d0
              if (m_1 <= (-0.08d0)) then
                  tmp = t_0
              else if (m_1 <= 3.7d-268) then
                  tmp = 1.0d0 * exp(((-0.25d0) * (m * m)))
              else if (m_1 <= 27.0d0) then
                  tmp = 1.0d0 * exp(-l)
              else
                  tmp = t_0
              end if
              code = tmp
          end function
          
          public static double code(double K, double m, double n, double M, double l) {
          	double t_0 = Math.exp((-M * M)) * 1.0;
          	double tmp;
          	if (M <= -0.08) {
          		tmp = t_0;
          	} else if (M <= 3.7e-268) {
          		tmp = 1.0 * Math.exp((-0.25 * (m * m)));
          	} else if (M <= 27.0) {
          		tmp = 1.0 * Math.exp(-l);
          	} 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 <= -0.08:
          		tmp = t_0
          	elif M <= 3.7e-268:
          		tmp = 1.0 * math.exp((-0.25 * (m * m)))
          	elif M <= 27.0:
          		tmp = 1.0 * math.exp(-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 <= -0.08)
          		tmp = t_0;
          	elseif (M <= 3.7e-268)
          		tmp = Float64(1.0 * exp(Float64(-0.25 * Float64(m * m))));
          	elseif (M <= 27.0)
          		tmp = Float64(1.0 * exp(Float64(-l)));
          	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 <= -0.08)
          		tmp = t_0;
          	elseif (M <= 3.7e-268)
          		tmp = 1.0 * exp((-0.25 * (m * m)));
          	elseif (M <= 27.0)
          		tmp = 1.0 * exp(-l);
          	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, -0.08], t$95$0, If[LessEqual[M, 3.7e-268], N[(1.0 * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 27.0], N[(1.0 * N[Exp[(-l)], $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 -0.08:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;M \leq 3.7 \cdot 10^{-268}:\\
          \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\
          
          \mathbf{elif}\;M \leq 27:\\
          \;\;\;\;1 \cdot e^{-\ell}\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if M < -0.0800000000000000017 or 27 < M

            1. Initial program 80.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.f6421.4

                \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
            5. Applied rewrites21.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^{\mathsf{neg}\left(\ell\right)} \]
            7. Step-by-step derivation
              1. cos-negN/A

                \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
              2. lower-cos.f6425.2

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

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

              \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
            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.f6496.8

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

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

              if -0.0800000000000000017 < M < 3.70000000000000018e-268

              1. Initial program 70.9%

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

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

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

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

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

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

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

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

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

                  \[\leadsto \color{blue}{\cos M} \cdot e^{\left(m \cdot m\right) \cdot -0.25} \]
              8. Applied rewrites68.9%

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

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

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

                if 3.70000000000000018e-268 < M < 27

                1. Initial program 77.5%

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

                    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
                5. Applied rewrites49.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^{\mathsf{neg}\left(\ell\right)} \]
                7. Step-by-step derivation
                  1. cos-negN/A

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

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

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

                  \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                10. Step-by-step derivation
                  1. Applied rewrites56.5%

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

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

                Alternative 7: 65.7% accurate, 2.8× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -6600:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.5 \cdot 10^{-223}:\\ \;\;\;\;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 -6600.0)
                   (* 1.0 (exp (* -0.25 (* m m))))
                   (if (<= m -1.5e-223)
                     (* (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 <= -6600.0) {
                		tmp = 1.0 * exp((-0.25 * (m * m)));
                	} else if (m <= -1.5e-223) {
                		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 <= (-6600.0d0)) then
                        tmp = 1.0d0 * exp(((-0.25d0) * (m * m)))
                    else if (m <= (-1.5d-223)) 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 <= -6600.0) {
                		tmp = 1.0 * Math.exp((-0.25 * (m * m)));
                	} else if (m <= -1.5e-223) {
                		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 <= -6600.0:
                		tmp = 1.0 * math.exp((-0.25 * (m * m)))
                	elif m <= -1.5e-223:
                		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 <= -6600.0)
                		tmp = Float64(1.0 * exp(Float64(-0.25 * Float64(m * m))));
                	elseif (m <= -1.5e-223)
                		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 <= -6600.0)
                		tmp = 1.0 * exp((-0.25 * (m * m)));
                	elseif (m <= -1.5e-223)
                		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, -6600.0], N[(1.0 * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, -1.5e-223], 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 -6600:\\
                \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\
                
                \mathbf{elif}\;m \leq -1.5 \cdot 10^{-223}:\\
                \;\;\;\;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 < -6600

                  1. Initial program 73.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

                    if -6600 < m < -1.49999999999999996e-223

                    1. Initial program 82.7%

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

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

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

                        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
                    5. Applied rewrites35.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^{\mathsf{neg}\left(\ell\right)} \]
                    7. Step-by-step derivation
                      1. cos-negN/A

                        \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                      2. lower-cos.f6443.7

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

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

                      \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                    10. Step-by-step derivation
                      1. Applied rewrites43.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.f6466.4

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

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

                      if -1.49999999999999996e-223 < m

                      1. Initial program 77.6%

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

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

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

                          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
                      5. Applied rewrites34.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^{\mathsf{neg}\left(\ell\right)} \]
                      7. Step-by-step derivation
                        1. cos-negN/A

                          \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                        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^{\mathsf{neg}\left(\ell\right)} \]
                      10. Step-by-step derivation
                        1. Applied rewrites37.0%

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

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

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

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

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

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

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

                        \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -6600:\\ \;\;\;\;1 \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.5 \cdot 10^{-223}:\\ \;\;\;\;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: 67.4% accurate, 2.9× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(-M\right) \cdot M} \cdot 1\\ \mathbf{if}\;M \leq -2.9 \cdot 10^{-67}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;1 \cdot e^{-\ell}\\ \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 -2.9e-67) t_0 (if (<= M 27.0) (* 1.0 (exp (- 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 <= -2.9e-67) {
                      		tmp = t_0;
                      	} else if (M <= 27.0) {
                      		tmp = 1.0 * exp(-l);
                      	} else {
                      		tmp = t_0;
                      	}
                      	return tmp;
                      }
                      
                      real(8) function code(k, m, n, m_1, l)
                          real(8), intent (in) :: k
                          real(8), intent (in) :: m
                          real(8), intent (in) :: n
                          real(8), intent (in) :: m_1
                          real(8), intent (in) :: l
                          real(8) :: t_0
                          real(8) :: tmp
                          t_0 = exp((-m_1 * m_1)) * 1.0d0
                          if (m_1 <= (-2.9d-67)) then
                              tmp = t_0
                          else if (m_1 <= 27.0d0) then
                              tmp = 1.0d0 * exp(-l)
                          else
                              tmp = t_0
                          end if
                          code = tmp
                      end function
                      
                      public static double code(double K, double m, double n, double M, double l) {
                      	double t_0 = Math.exp((-M * M)) * 1.0;
                      	double tmp;
                      	if (M <= -2.9e-67) {
                      		tmp = t_0;
                      	} else if (M <= 27.0) {
                      		tmp = 1.0 * Math.exp(-l);
                      	} 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 <= -2.9e-67:
                      		tmp = t_0
                      	elif M <= 27.0:
                      		tmp = 1.0 * math.exp(-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 <= -2.9e-67)
                      		tmp = t_0;
                      	elseif (M <= 27.0)
                      		tmp = Float64(1.0 * exp(Float64(-l)));
                      	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 <= -2.9e-67)
                      		tmp = t_0;
                      	elseif (M <= 27.0)
                      		tmp = 1.0 * exp(-l);
                      	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, -2.9e-67], t$95$0, If[LessEqual[M, 27.0], N[(1.0 * N[Exp[(-l)], $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 -2.9 \cdot 10^{-67}:\\
                      \;\;\;\;t\_0\\
                      
                      \mathbf{elif}\;M \leq 27:\\
                      \;\;\;\;1 \cdot e^{-\ell}\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;t\_0\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if M < -2.90000000000000005e-67 or 27 < M

                        1. Initial program 79.3%

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

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

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

                            \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
                        5. Applied rewrites20.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^{\mathsf{neg}\left(\ell\right)} \]
                        7. Step-by-step derivation
                          1. cos-negN/A

                            \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                          2. lower-cos.f6424.0

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

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

                          \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                        10. Step-by-step derivation
                          1. Applied rewrites23.4%

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

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

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

                          if -2.90000000000000005e-67 < M < 27

                          1. Initial program 75.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.f6446.9

                              \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
                          5. Applied rewrites46.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^{\mathsf{neg}\left(\ell\right)} \]
                          7. Step-by-step derivation
                            1. cos-negN/A

                              \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                            2. lower-cos.f6453.6

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

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

                            \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                          10. Step-by-step derivation
                            1. Applied rewrites53.6%

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

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

                          Alternative 9: 35.3% accurate, 3.3× speedup?

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

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

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

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

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

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

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

                              \[\leadsto \color{blue}{\cos M} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                            2. lower-cos.f6435.9

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

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

                            \[\leadsto 1 \cdot e^{\mathsf{neg}\left(\ell\right)} \]
                          10. Step-by-step derivation
                            1. Applied rewrites35.6%

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

                            Reproduce

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