Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.7% → 97.1%
Time: 12.7s
Alternatives: 9
Speedup: 2.6×

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: 75.7% 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: 97.1% accurate, 1.1× speedup?

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

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

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

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

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

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

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

Alternative 2: 96.0% accurate, 1.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -0.17499999999999999

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

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

      \[\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 M around inf

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

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

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

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

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

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

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

    if -0.17499999999999999 < M < 27

    1. Initial program 71.8%

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

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\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.f6498.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. Simplified98.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. Taylor expanded in M around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 27 < M

    1. Initial program 75.0%

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

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

      \[\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 M around inf

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{M \cdot \color{blue}{\left(-M\right)}} \]
    8. Simplified100.0%

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

      \[\leadsto \color{blue}{1} \cdot e^{M \cdot \left(\mathsf{neg}\left(M\right)\right)} \]
    10. Step-by-step derivation
      1. Simplified100.0%

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

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

    Alternative 3: 96.0% accurate, 2.6× speedup?

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

      1. Initial program 77.7%

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

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

        \[\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 M around inf

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{1} \cdot e^{M \cdot \left(\mathsf{neg}\left(M\right)\right)} \]
      10. Step-by-step derivation
        1. Simplified97.6%

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

        if -0.17499999999999999 < M < 27

        1. Initial program 71.8%

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

          \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\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.f6498.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. Simplified98.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. Taylor expanded in M around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 4: 66.2% accurate, 2.9× speedup?

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

        1. Initial program 70.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -0.104999999999999996 < m < -2.59999999999999989e-288

        1. Initial program 81.8%

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

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

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

          \[\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 M around inf

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{1} \cdot e^{M \cdot \left(\mathsf{neg}\left(M\right)\right)} \]
        10. Step-by-step derivation
          1. Simplified61.2%

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

          if -2.59999999999999989e-288 < m

          1. Initial program 73.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
            3. associate-*l*N/A

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

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

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

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

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

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

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

        Alternative 5: 64.4% accurate, 2.9× speedup?

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

          1. Initial program 69.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
          11. Simplified97.4%

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

          if -42 < m < -1.14999999999999994e-157

          1. Initial program 90.0%

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

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

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

            \[\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 M around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto e^{\color{blue}{-\ell}} \]
          11. Simplified54.6%

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

          if -1.14999999999999994e-157 < m

          1. Initial program 73.5%

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

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

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

            \[\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 M around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
            3. associate-*l*N/A

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

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

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

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

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

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

        Alternative 6: 68.5% accurate, 2.9× speedup?

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

          1. Initial program 68.9%

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

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

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

            \[\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 M around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
            3. associate-*l*N/A

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

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

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

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

              \[\leadsto e^{n \cdot \color{blue}{\left(n \cdot -0.25\right)}} \]
          11. Simplified94.0%

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

          if -2.9e19 < n < 4.29999999999999998e-14

          1. Initial program 80.1%

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

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

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

            \[\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 M around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto e^{\color{blue}{-\ell}} \]
        3. Recombined 2 regimes into one program.
        4. Add Preprocessing

        Alternative 7: 35.8% accurate, 3.5× speedup?

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

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

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

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

          \[\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 M around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto e^{\color{blue}{-\ell}} \]
        11. Simplified35.6%

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

        Alternative 8: 7.3% accurate, 3.6× speedup?

        \[\begin{array}{l} \\ \cos M \end{array} \]
        (FPCore (K m n M l) :precision binary64 (cos M))
        double code(double K, double m, double n, double M, double l) {
        	return 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 = cos(m_1)
        end function
        
        public static double code(double K, double m, double n, double M, double l) {
        	return Math.cos(M);
        }
        
        def code(K, m, n, M, l):
        	return math.cos(M)
        
        function code(K, m, n, M, l)
        	return cos(M)
        end
        
        function tmp = code(K, m, n, M, l)
        	tmp = cos(M);
        end
        
        code[K_, m_, n_, M_, l_] := N[Cos[M], $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \cos M
        \end{array}
        
        Derivation
        1. Initial program 74.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 n around inf

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot m\right) - M\right)} \]
          2. sub-negN/A

            \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot m\right) + \left(\mathsf{neg}\left(M\right)\right)\right)} \]
          3. associate-*r*N/A

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

            \[\leadsto \cos \color{blue}{\left(\mathsf{fma}\left(\frac{1}{2} \cdot K, m, \mathsf{neg}\left(M\right)\right)\right)} \]
          5. lower-*.f64N/A

            \[\leadsto \cos \left(\mathsf{fma}\left(\color{blue}{\frac{1}{2} \cdot K}, m, \mathsf{neg}\left(M\right)\right)\right) \]
          6. lower-neg.f648.1

            \[\leadsto \cos \left(\mathsf{fma}\left(0.5 \cdot K, m, \color{blue}{-M}\right)\right) \]
        8. Simplified8.1%

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

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

            \[\leadsto \color{blue}{\cos M} \]
          2. lower-cos.f648.6

            \[\leadsto \color{blue}{\cos M} \]
        11. Simplified8.6%

          \[\leadsto \color{blue}{\cos M} \]
        12. Add Preprocessing

        Alternative 9: 7.3% accurate, 359.0× speedup?

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

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

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

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

          \[\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 M around inf

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{1} \]
        10. Step-by-step derivation
          1. Simplified8.6%

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

          Reproduce

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