Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.7% → 96.0%
Time: 13.3s
Alternatives: 10
Speedup: 2.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 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: 96.0% accurate, 0.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;e^{t\_0 - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)}\\


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

    1. Initial program 95.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 M around 0

      \[\leadsto \color{blue}{\left(\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right) + M \cdot \sin \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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. +-commutativeN/A

        \[\leadsto \color{blue}{\left(M \cdot \sin \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right) + \cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right), \cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      3. lower-sin.f64N/A

        \[\leadsto \mathsf{fma}\left(M, \color{blue}{\sin \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right)}, \cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(M, \sin \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right)}, \cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\right), \cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      6. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\right), \cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\right)\right), \cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      8. lower-+.f64N/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\right)\right), \cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      9. lower-cos.f64N/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \left(\left(n + m\right) \cdot K\right)\right), \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      10. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \left(\left(n + m\right) \cdot K\right)\right), \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\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)} \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \left(\left(n + m\right) \cdot K\right)\right), \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\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)} \]
      12. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \left(\left(n + m\right) \cdot K\right)\right), \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\right)}\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)} \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(M, \sin \left(\frac{1}{2} \cdot \left(\left(n + m\right) \cdot K\right)\right), \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\right)\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)} \]
      14. lower-+.f6496.2

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

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

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

    1. Initial program 0.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in 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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.6%

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

Alternative 2: 95.4% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -126:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 45:\\ \;\;\;\;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 -126.0)
     t_0
     (if (<= M 45.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 <= -126.0) {
		tmp = t_0;
	} else if (M <= 45.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 <= -126.0)
		tmp = t_0;
	elseif (M <= 45.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, -126.0], t$95$0, If[LessEqual[M, 45.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 -126:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 45:\\
\;\;\;\;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 < -126 or 45 < M

    1. Initial program 77.6%

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6477.6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -126 < M < 45

    1. Initial program 75.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.f6492.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. Simplified92.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 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-+.f6492.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. Simplified92.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)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -126:\\ \;\;\;\;e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;M \leq 45:\\ \;\;\;\;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} \]
  5. Add Preprocessing

Alternative 3: 96.0% accurate, 2.6× speedup?

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

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

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

    \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
    2. lower-*.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
    3. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
    5. +-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
    6. lower-+.f6476.3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 61.7% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -530000000:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;m \leq -2.45 \cdot 10^{-296}:\\ \;\;\;\;e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|m - n\right| - 0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -530000000.0)
   (exp (* (* m m) -0.25))
   (if (<= m -2.45e-296)
     (exp (* M (- M)))
     (exp (- (fabs (- m n)) (* 0.25 (* n n)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -530000000.0) {
		tmp = exp(((m * m) * -0.25));
	} else if (m <= -2.45e-296) {
		tmp = exp((M * -M));
	} else {
		tmp = exp((fabs((m - n)) - (0.25 * (n * n))));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: tmp
    if (m <= (-530000000.0d0)) then
        tmp = exp(((m * m) * (-0.25d0)))
    else if (m <= (-2.45d-296)) then
        tmp = exp((m_1 * -m_1))
    else
        tmp = exp((abs((m - n)) - (0.25d0 * (n * n))))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -530000000.0) {
		tmp = Math.exp(((m * m) * -0.25));
	} else if (m <= -2.45e-296) {
		tmp = Math.exp((M * -M));
	} else {
		tmp = Math.exp((Math.abs((m - n)) - (0.25 * (n * n))));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -530000000.0:
		tmp = math.exp(((m * m) * -0.25))
	elif m <= -2.45e-296:
		tmp = math.exp((M * -M))
	else:
		tmp = math.exp((math.fabs((m - n)) - (0.25 * (n * n))))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -530000000.0)
		tmp = exp(Float64(Float64(m * m) * -0.25));
	elseif (m <= -2.45e-296)
		tmp = exp(Float64(M * Float64(-M)));
	else
		tmp = exp(Float64(abs(Float64(m - n)) - Float64(0.25 * Float64(n * n))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -530000000.0)
		tmp = exp(((m * m) * -0.25));
	elseif (m <= -2.45e-296)
		tmp = exp((M * -M));
	else
		tmp = exp((abs((m - n)) - (0.25 * (n * n))));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -530000000.0], N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -2.45e-296], N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision], N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -530000000:\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

\mathbf{elif}\;m \leq -2.45 \cdot 10^{-296}:\\
\;\;\;\;e^{M \cdot \left(-M\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < -5.3e8

    1. Initial program 65.0%

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6465.0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.5 \cdot \left(n + m\right) - M, 0.5 \cdot \left(n + m\right) - M, \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-*.f6498.4

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

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

    if -5.3e8 < m < -2.4499999999999999e-296

    1. Initial program 81.6%

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6481.6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{M \cdot \color{blue}{\left(-M\right)}} \]
    11. Simplified62.6%

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

    if -2.4499999999999999e-296 < m

    1. Initial program 78.9%

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6478.9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 64.3% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -530000000:\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

\mathbf{elif}\;m \leq 2 \cdot 10^{-194}:\\
\;\;\;\;e^{M \cdot \left(-M\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < -5.3e8

    1. Initial program 65.0%

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6465.0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.5 \cdot \left(n + m\right) - M, 0.5 \cdot \left(n + m\right) - M, \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-*.f6498.4

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

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

    if -5.3e8 < m < 2.00000000000000004e-194

    1. Initial program 83.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 M around 0

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6483.1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000004e-194 < m

    1. Initial program 77.0%

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6477.0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.5 \cdot \left(n + m\right) - M, 0.5 \cdot \left(n + m\right) - M, \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. lower-*.f64N/A

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

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

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

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

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

Alternative 6: 76.7% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -110:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 1.2 \cdot 10^{-11}:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* M (- M)))))
   (if (<= M -110.0) t_0 (if (<= M 1.2e-11) (exp (* (* m m) -0.25)) t_0))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((M * -M));
	double tmp;
	if (M <= -110.0) {
		tmp = t_0;
	} else if (M <= 1.2e-11) {
		tmp = exp(((m * m) * -0.25));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: tmp
    t_0 = exp((m_1 * -m_1))
    if (m_1 <= (-110.0d0)) then
        tmp = t_0
    else if (m_1 <= 1.2d-11) then
        tmp = exp(((m * m) * (-0.25d0)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((M * -M));
	double tmp;
	if (M <= -110.0) {
		tmp = t_0;
	} else if (M <= 1.2e-11) {
		tmp = Math.exp(((m * m) * -0.25));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((M * -M))
	tmp = 0
	if M <= -110.0:
		tmp = t_0
	elif M <= 1.2e-11:
		tmp = math.exp(((m * m) * -0.25))
	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 <= -110.0)
		tmp = t_0;
	elseif (M <= 1.2e-11)
		tmp = exp(Float64(Float64(m * m) * -0.25));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp((M * -M));
	tmp = 0.0;
	if (M <= -110.0)
		tmp = t_0;
	elseif (M <= 1.2e-11)
		tmp = exp(((m * m) * -0.25));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[M, -110.0], t$95$0, If[LessEqual[M, 1.2e-11], N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

\mathbf{elif}\;M \leq 1.2 \cdot 10^{-11}:\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -110 or 1.2000000000000001e-11 < M

    1. Initial program 77.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 M around 0

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6477.8

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -110 < M < 1.2000000000000001e-11

    1. Initial program 74.9%

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6474.9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.5 \cdot \left(n + m\right) - M, 0.5 \cdot \left(n + m\right) - M, \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-*.f6458.8

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

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

Alternative 7: 68.5% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -2.75 \cdot 10^{-5}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 4 \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 (* M (- M)))))
   (if (<= M -2.75e-5) t_0 (if (<= M 4e-14) (exp (- 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 <= -2.75e-5) {
		tmp = t_0;
	} else if (M <= 4e-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((m_1 * -m_1))
    if (m_1 <= (-2.75d-5)) then
        tmp = t_0
    else if (m_1 <= 4d-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((M * -M));
	double tmp;
	if (M <= -2.75e-5) {
		tmp = t_0;
	} else if (M <= 4e-14) {
		tmp = Math.exp(-l);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((M * -M))
	tmp = 0
	if M <= -2.75e-5:
		tmp = t_0
	elif M <= 4e-14:
		tmp = math.exp(-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 <= -2.75e-5)
		tmp = t_0;
	elseif (M <= 4e-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((M * -M));
	tmp = 0.0;
	if (M <= -2.75e-5)
		tmp = t_0;
	elseif (M <= 4e-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[(M * (-M)), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[M, -2.75e-5], t$95$0, If[LessEqual[M, 4e-14], N[Exp[(-l)], $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

\mathbf{elif}\;M \leq 4 \cdot 10^{-14}:\\
\;\;\;\;e^{-\ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -2.7500000000000001e-5 or 4e-14 < M

    1. Initial program 77.5%

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6477.5

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.7500000000000001e-5 < M < 4e-14

    1. Initial program 75.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 M around 0

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      2. lower-*.f64N/A

        \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
      3. *-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
      5. +-commutativeN/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
      6. lower-+.f6475.1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 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 76.3%

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

    \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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. lower-cos.f64N/A

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
    2. lower-*.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\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)} \]
    3. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\left(\left(m + n\right) \cdot K\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)} \]
    5. +-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{2} \cdot \left(\color{blue}{\left(n + m\right)} \cdot K\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)} \]
    6. lower-+.f6476.3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-\ell}} \]
  11. Simplified32.4%

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

Alternative 9: 7.0% 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 76.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \]
    2. lower-cos.f647.5

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified7.5%

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

Alternative 10: 7.0% 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 76.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \]
    2. lower-cos.f647.5

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified7.5%

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

    \[\leadsto \color{blue}{1} \]
  13. Step-by-step derivation
    1. Simplified7.5%

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

    Reproduce

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