Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.6% → 96.7%
Time: 15.3s
Alternatives: 8
Speedup: 2.6×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 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.6% accurate, 1.0× speedup?

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

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

Alternative 1: 96.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\ \mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_0 \leq \infty:\\ \;\;\;\;t\_0 \cdot \cos \left(\frac{K}{\frac{2}{m + n}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- (- (fabs (- m n)) l) (pow (- (/ (+ m n) 2.0) M) 2.0)))))
   (if (<= (* (cos (- (/ (* K (+ m n)) 2.0) M)) t_0) INFINITY)
     (* t_0 (cos (- (/ K (/ 2.0 (+ m n))) M)))
     (* t_0 (cos (* K 0.5))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(((fabs((m - n)) - l) - pow((((m + n) / 2.0) - M), 2.0)));
	double tmp;
	if ((cos((((K * (m + n)) / 2.0) - M)) * t_0) <= ((double) INFINITY)) {
		tmp = t_0 * cos(((K / (2.0 / (m + n))) - M));
	} else {
		tmp = t_0 * cos((K * 0.5));
	}
	return tmp;
}
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(((Math.abs((m - n)) - l) - Math.pow((((m + n) / 2.0) - M), 2.0)));
	double tmp;
	if ((Math.cos((((K * (m + n)) / 2.0) - M)) * t_0) <= Double.POSITIVE_INFINITY) {
		tmp = t_0 * Math.cos(((K / (2.0 / (m + n))) - M));
	} else {
		tmp = t_0 * Math.cos((K * 0.5));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp(((math.fabs((m - n)) - l) - math.pow((((m + n) / 2.0) - M), 2.0)))
	tmp = 0
	if (math.cos((((K * (m + n)) / 2.0) - M)) * t_0) <= math.inf:
		tmp = t_0 * math.cos(((K / (2.0 / (m + n))) - M))
	else:
		tmp = t_0 * math.cos((K * 0.5))
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))
	tmp = 0.0
	if (Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * t_0) <= Inf)
		tmp = Float64(t_0 * cos(Float64(Float64(K / Float64(2.0 / Float64(m + n))) - M)));
	else
		tmp = Float64(t_0 * cos(Float64(K * 0.5)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((abs((m - n)) - l) - ((((m + n) / 2.0) - M) ^ 2.0)));
	tmp = 0.0;
	if ((cos((((K * (m + n)) / 2.0) - M)) * t_0) <= Inf)
		tmp = t_0 * cos(((K / (2.0 / (m + n))) - M));
	else
		tmp = t_0 * cos((K * 0.5));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], Infinity], N[(t$95$0 * N[Cos[N[(N[(K / N[(2.0 / N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
\mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_0 \leq \infty:\\
\;\;\;\;t\_0 \cdot \cos \left(\frac{K}{\frac{2}{m + n}} - M\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \cos \left(K \cdot 0.5\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 99.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

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

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

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

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

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

      \[\leadsto \cos \left(\color{blue}{\left(0.5 \cdot K\right) \cdot n} - M\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 inf

      \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot K\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. Step-by-step derivation
      1. lower-*.f64100.0

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

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot K\right)} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.3%

    \[\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 \cos \left(\frac{K}{\frac{2}{m + n}} - M\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.6% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;t\_2 \cdot \cos \left(K \cdot 0.5\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 99.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 \cos \left(\color{blue}{\frac{1}{2} \cdot \left(K \cdot n\right)} - M\right) \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. associate-*r*N/A

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

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

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

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

      \[\leadsto \color{blue}{e^{-\mathsf{fma}\left(\mathsf{fma}\left(m + n, 0.5, -M\right), \mathsf{fma}\left(m + n, 0.5, -M\right), \ell - \left|m - n\right|\right)} \cdot \cos \left(\mathsf{fma}\left(n, 0.5 \cdot K, -M\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 m around 0

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

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

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

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

      \[\leadsto \cos \left(\color{blue}{\left(0.5 \cdot K\right) \cdot n} - M\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 inf

      \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot K\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. Step-by-step derivation
      1. lower-*.f64100.0

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

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot K\right)} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.8%

    \[\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^{-\mathsf{fma}\left(\mathsf{fma}\left(m + n, 0.5, -M\right), \mathsf{fma}\left(m + n, 0.5, -M\right), \ell - \left|m - n\right|\right)} \cdot \cos \left(\mathsf{fma}\left(n, K \cdot 0.5, -M\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 96.1% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(m + n\right) \cdot 0.5 - 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 (- (* (+ m n) 0.5) 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 = ((m + n) * 0.5) - M;
	return exp((fabs((m - n)) - fma(t_0, t_0, l)));
}
function code(K, m, n, M, l)
	t_0 = Float64(Float64(Float64(m + n) * 0.5) - 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[(N[(m + n), $MachinePrecision] * 0.5), $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 := \left(m + n\right) \cdot 0.5 - M\\
e^{\left|m - n\right| - \mathsf{fma}\left(t\_0, t\_0, \ell\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 79.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 \cos \left(\color{blue}{\frac{1}{2} \cdot \left(K \cdot n\right)} - M\right) \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
  4. Step-by-step derivation
    1. associate-*r*N/A

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

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

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

    \[\leadsto \cos \left(\color{blue}{\left(0.5 \cdot K\right) \cdot n} - M\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 inf

    \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot K\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. Step-by-step derivation
    1. lower-*.f6496.8

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\left|m - n\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)} \]
      11. lower-fma.f64N/A

        \[\leadsto e^{\left|m - n\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)}} \]
      12. lower--.f64N/A

        \[\leadsto e^{\left|m - n\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)} \]
      13. lower-*.f64N/A

        \[\leadsto e^{\left|m - n\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. +-commutativeN/A

        \[\leadsto e^{\left|m - n\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)} \]
      15. lower-+.f64N/A

        \[\leadsto e^{\left|m - n\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|m - n\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)} \]
      17. lower-*.f64N/A

        \[\leadsto e^{\left|m - n\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. +-commutativeN/A

        \[\leadsto e^{\left|m - n\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)} \]
      19. lower-+.f6497.2

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

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

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

    Alternative 4: 42.7% accurate, 2.7× speedup?

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

      1. Initial program 81.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto e^{\color{blue}{-\ell}} \]
      11. Simplified34.0%

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

      if -5.5000000000000002e-47 < M < 4.10000000000000026e-101

      1. Initial program 77.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\frac{-1}{2}, \color{blue}{M \cdot M}, 1\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        4. lower-*.f6437.3

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

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

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

          \[\leadsto \color{blue}{\left(\frac{-1}{2} \cdot {M}^{3}\right)} \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        2. cube-multN/A

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

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

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

          \[\leadsto \left(\frac{-1}{2} \cdot \left(M \cdot \color{blue}{\left(M \cdot M\right)}\right)\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
        6. lower-*.f6457.0

          \[\leadsto \left(-0.5 \cdot \left(M \cdot \color{blue}{\left(M \cdot M\right)}\right)\right) \cdot e^{-\ell} \]
      14. Simplified57.0%

        \[\leadsto \color{blue}{\left(-0.5 \cdot \left(M \cdot \left(M \cdot M\right)\right)\right)} \cdot e^{-\ell} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification42.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -5.5 \cdot 10^{-47}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{elif}\;M \leq 4.1 \cdot 10^{-101}:\\ \;\;\;\;e^{-\ell} \cdot \left(-0.5 \cdot \left(M \cdot \left(M \cdot M\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 5: 36.1% 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 79.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 6: 9.2% accurate, 10.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-1}{2}, \color{blue}{M \cdot M}, 1\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
      4. lower-*.f6427.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, M \cdot M, 1\right)} \cdot e^{-\ell} \]
    12. Taylor expanded in l around 0

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-0.5, M \cdot M, 1\right) \cdot \mathsf{fma}\left(\ell, \mathsf{fma}\left(\ell, \color{blue}{\mathsf{fma}\left(-0.16666666666666666, \ell, 0.5\right)}, -1\right), 1\right) \]
    14. Simplified10.4%

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

    Alternative 7: 8.5% accurate, 12.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{-1}{2}, \color{blue}{M \cdot M}, 1\right) \cdot e^{\mathsf{neg}\left(\ell\right)} \]
      4. lower-*.f6427.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, M \cdot M, 1\right)} \cdot e^{-\ell} \]
    12. Taylor expanded in l around 0

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-0.5, M \cdot M, 1\right) \cdot \mathsf{fma}\left(\ell, \color{blue}{\mathsf{fma}\left(0.5, \ell, -1\right)}, 1\right) \]
    14. Simplified9.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Reproduce

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