Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.9% → 96.8%
Time: 26.2s
Alternatives: 7
Speedup: 2.0×

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 7 alternatives:

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

Initial Program: 76.9% 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.8% accurate, 1.0× speedup?

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

\\
\cos M \cdot e^{\left(\left|n - m\right| - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 76.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. Taylor expanded in K around 0 96.4%

    \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)}} \]
  3. Step-by-step derivation
    1. cos-neg96.4%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
    2. associate--r+96.4%

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

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

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

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

Alternative 2: 87.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|n - m\right|\\ \mathbf{if}\;n \leq 1.06 \cdot 10^{-237}:\\ \;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}\\ \mathbf{elif}\;n \leq 1.18 \cdot 10^{-5}:\\ \;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(\left(M - m \cdot 0.5\right) - n\right) + \left(t_0 - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{t_0 - 0.25 \cdot {\left(m + n\right)}^{2}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- n m))))
   (if (<= n 1.06e-237)
     (exp (- t_0 (+ l (* 0.25 (* (+ m n) (+ m n))))))
     (if (<= n 1.18e-5)
       (*
        (cos (- (/ (* (+ m n) K) 2.0) M))
        (exp (+ (* (- (* m 0.5) M) (- (- M (* m 0.5)) n)) (- t_0 l))))
       (exp (- t_0 (* 0.25 (pow (+ m n) 2.0))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((n - m));
	double tmp;
	if (n <= 1.06e-237) {
		tmp = exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	} else if (n <= 1.18e-5) {
		tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) + (t_0 - l)));
	} else {
		tmp = exp((t_0 - (0.25 * pow((m + n), 2.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 = abs((n - m))
    if (n <= 1.06d-237) then
        tmp = exp((t_0 - (l + (0.25d0 * ((m + n) * (m + n))))))
    else if (n <= 1.18d-5) then
        tmp = cos(((((m + n) * k) / 2.0d0) - m_1)) * exp(((((m * 0.5d0) - m_1) * ((m_1 - (m * 0.5d0)) - n)) + (t_0 - l)))
    else
        tmp = exp((t_0 - (0.25d0 * ((m + n) ** 2.0d0))))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.abs((n - m));
	double tmp;
	if (n <= 1.06e-237) {
		tmp = Math.exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	} else if (n <= 1.18e-5) {
		tmp = Math.cos(((((m + n) * K) / 2.0) - M)) * Math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) + (t_0 - l)));
	} else {
		tmp = Math.exp((t_0 - (0.25 * Math.pow((m + n), 2.0))));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((n - m))
	tmp = 0
	if n <= 1.06e-237:
		tmp = math.exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))))
	elif n <= 1.18e-5:
		tmp = math.cos(((((m + n) * K) / 2.0) - M)) * math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) + (t_0 - l)))
	else:
		tmp = math.exp((t_0 - (0.25 * math.pow((m + n), 2.0))))
	return tmp
function code(K, m, n, M, l)
	t_0 = abs(Float64(n - m))
	tmp = 0.0
	if (n <= 1.06e-237)
		tmp = exp(Float64(t_0 - Float64(l + Float64(0.25 * Float64(Float64(m + n) * Float64(m + n))))));
	elseif (n <= 1.18e-5)
		tmp = Float64(cos(Float64(Float64(Float64(Float64(m + n) * K) / 2.0) - M)) * exp(Float64(Float64(Float64(Float64(m * 0.5) - M) * Float64(Float64(M - Float64(m * 0.5)) - n)) + Float64(t_0 - l))));
	else
		tmp = exp(Float64(t_0 - Float64(0.25 * (Float64(m + n) ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((n - m));
	tmp = 0.0;
	if (n <= 1.06e-237)
		tmp = exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	elseif (n <= 1.18e-5)
		tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) + (t_0 - l)));
	else
		tmp = exp((t_0 - (0.25 * ((m + n) ^ 2.0))));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, 1.06e-237], N[Exp[N[(t$95$0 - N[(l + N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[n, 1.18e-5], N[(N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision] - n), $MachinePrecision]), $MachinePrecision] + N[(t$95$0 - l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(t$95$0 - N[(0.25 * N[Power[N[(m + n), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|n - m\right|\\
\mathbf{if}\;n \leq 1.06 \cdot 10^{-237}:\\
\;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}\\

\mathbf{elif}\;n \leq 1.18 \cdot 10^{-5}:\\
\;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(\left(M - m \cdot 0.5\right) - n\right) + \left(t_0 - \ell\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < 1.05999999999999994e-237

    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. Taylor expanded in K around 0 94.7%

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)}} \]
    3. Step-by-step derivation
      1. cos-neg94.7%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
      2. associate--r+94.7%

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\color{blue}{\left(m + n\right) \cdot 0.5} - M\right)}^{2}} \]
    4. Simplified94.7%

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}} \]
    6. Step-by-step derivation
      1. +-commutative87.0%

        \[\leadsto e^{\left|m - n\right| - \color{blue}{\left(0.25 \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      2. +-commutative87.0%

        \[\leadsto e^{\left|m - n\right| - \left(0.25 \cdot {\color{blue}{\left(n + m\right)}}^{2} + \ell\right)} \]
    7. Simplified87.0%

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(0.25 \cdot {\left(n + m\right)}^{2} + \ell\right)}} \]
    8. Step-by-step derivation
      1. +-commutative87.0%

        \[\leadsto e^{\left|m - n\right| - \left(0.25 \cdot {\color{blue}{\left(m + n\right)}}^{2} + \ell\right)} \]
      2. pow287.0%

        \[\leadsto e^{\left|m - n\right| - \left(0.25 \cdot \color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} + \ell\right)} \]
    9. Applied egg-rr87.0%

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

    if 1.05999999999999994e-237 < n < 1.18000000000000005e-5

    1. Initial program 76.2%

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(n \cdot \left(0.5 \cdot m - M\right) + {\left(0.5 \cdot m - M\right)}^{2}\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
    3. Step-by-step derivation
      1. +-commutative76.2%

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

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

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

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

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

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

    if 1.18000000000000005e-5 < n

    1. Initial program 73.5%

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

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)}} \]
    3. Step-by-step derivation
      1. cos-neg100.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
      2. associate--r+100.0%

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}} \]
    6. Step-by-step derivation
      1. +-commutative98.6%

        \[\leadsto e^{\left|m - n\right| - \color{blue}{\left(0.25 \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      2. +-commutative98.6%

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(0.25 \cdot {\left(n + m\right)}^{2} + \ell\right)}} \]
    8. Taylor expanded in l around 0 100.0%

      \[\leadsto \color{blue}{e^{\left|m - n\right| - 0.25 \cdot {\left(m + n\right)}^{2}}} \]
    9. Step-by-step derivation
      1. fabs-sub100.0%

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - 0.25 \cdot {\left(m + n\right)}^{2}} \]
    10. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 1.06 \cdot 10^{-237}:\\ \;\;\;\;e^{\left|n - m\right| - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}\\ \mathbf{elif}\;n \leq 1.18 \cdot 10^{-5}:\\ \;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot e^{\left(m \cdot 0.5 - M\right) \cdot \left(\left(M - m \cdot 0.5\right) - n\right) + \left(\left|n - m\right| - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|n - m\right| - 0.25 \cdot {\left(m + n\right)}^{2}}\\ \end{array} \]

Alternative 3: 45.8% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -2.7 \cdot 10^{+17}:\\ \;\;\;\;\cos \left(\left(\left(m + n\right) \cdot 0.5\right) \cdot K - M\right) \cdot e^{m - \ell}\\ \mathbf{else}:\\ \;\;\;\;e^{0.25 \cdot {m}^{2} - \left(n + \ell\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -2.7e+17)
   (* (cos (- (* (* (+ m n) 0.5) K) M)) (exp (- m l)))
   (exp (- (* 0.25 (pow m 2.0)) (+ n l)))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -2.7e+17) {
		tmp = cos(((((m + n) * 0.5) * K) - M)) * exp((m - l));
	} else {
		tmp = exp(((0.25 * pow(m, 2.0)) - (n + l)));
	}
	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 <= (-2.7d+17)) then
        tmp = cos(((((m + n) * 0.5d0) * k) - m_1)) * exp((m - l))
    else
        tmp = exp(((0.25d0 * (m ** 2.0d0)) - (n + l)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -2.7e+17) {
		tmp = Math.cos(((((m + n) * 0.5) * K) - M)) * Math.exp((m - l));
	} else {
		tmp = Math.exp(((0.25 * Math.pow(m, 2.0)) - (n + l)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -2.7e+17:
		tmp = math.cos(((((m + n) * 0.5) * K) - M)) * math.exp((m - l))
	else:
		tmp = math.exp(((0.25 * math.pow(m, 2.0)) - (n + l)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -2.7e+17)
		tmp = Float64(cos(Float64(Float64(Float64(Float64(m + n) * 0.5) * K) - M)) * exp(Float64(m - l)));
	else
		tmp = exp(Float64(Float64(0.25 * (m ^ 2.0)) - Float64(n + l)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -2.7e+17)
		tmp = cos(((((m + n) * 0.5) * K) - M)) * exp((m - l));
	else
		tmp = exp(((0.25 * (m ^ 2.0)) - (n + l)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -2.7e+17], N[(N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision] * K), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(m - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[(0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision] - N[(n + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -2.7 \cdot 10^{+17}:\\
\;\;\;\;\cos \left(\left(\left(m + n\right) \cdot 0.5\right) \cdot K - M\right) \cdot e^{m - \ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -2.7e17

    1. Initial program 72.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. Applied egg-rr7.9%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)} - 1} \]
    3. Step-by-step derivation
      1. expm1-def7.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)\right)} \]
      2. expm1-log1p8.3%

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

        \[\leadsto \cos \color{blue}{\left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 - M\right)} \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)} \]
      4. associate-*r*8.3%

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

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

        \[\leadsto \cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(\ell - \left(m - n\right)\right)}} \]
      7. associate--r-8.3%

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

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

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

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

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

    if -2.7e17 < m

    1. Initial program 76.8%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Applied egg-rr19.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)} - 1} \]
    3. Step-by-step derivation
      1. expm1-def19.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)\right)} \]
      2. expm1-log1p20.7%

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

        \[\leadsto \cos \color{blue}{\left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 - M\right)} \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)} \]
      4. associate-*r*20.7%

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

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

        \[\leadsto \cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(\ell - \left(m - n\right)\right)}} \]
      7. associate--r-20.7%

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
    6. Step-by-step derivation
      1. cos-neg20.6%

        \[\leadsto \color{blue}{\cos M} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
    7. Simplified20.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -2.7 \cdot 10^{+17}:\\ \;\;\;\;\cos \left(\left(\left(m + n\right) \cdot 0.5\right) \cdot K - M\right) \cdot e^{m - \ell}\\ \mathbf{else}:\\ \;\;\;\;e^{0.25 \cdot {m}^{2} - \left(n + \ell\right)}\\ \end{array} \]

Alternative 4: 86.6% accurate, 2.0× speedup?

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

\\
e^{\left|n - m\right| - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}
\end{array}
Derivation
  1. Initial program 76.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. Taylor expanded in K around 0 96.4%

    \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)}} \]
  3. Step-by-step derivation
    1. cos-neg96.4%

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
    2. associate--r+96.4%

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

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

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

    \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}} \]
  6. Step-by-step derivation
    1. +-commutative87.2%

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

      \[\leadsto e^{\left|m - n\right| - \left(0.25 \cdot {\color{blue}{\left(n + m\right)}}^{2} + \ell\right)} \]
  7. Simplified87.2%

    \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(0.25 \cdot {\left(n + m\right)}^{2} + \ell\right)}} \]
  8. Step-by-step derivation
    1. +-commutative87.2%

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

      \[\leadsto e^{\left|m - n\right| - \left(0.25 \cdot \color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} + \ell\right)} \]
  9. Applied egg-rr87.2%

    \[\leadsto e^{\left|m - n\right| - \left(0.25 \cdot \color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} + \ell\right)} \]
  10. Final simplification87.2%

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

Alternative 5: 44.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 7.2 \cdot 10^{-31}:\\ \;\;\;\;e^{0.25 \cdot {m}^{2} - \left(n + \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= l 7.2e-31)
   (exp (- (* 0.25 (pow m 2.0)) (+ n l)))
   (* (cos M) (exp (- l)))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (l <= 7.2e-31) {
		tmp = exp(((0.25 * pow(m, 2.0)) - (n + l)));
	} else {
		tmp = cos(M) * exp(-l);
	}
	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 (l <= 7.2d-31) then
        tmp = exp(((0.25d0 * (m ** 2.0d0)) - (n + l)))
    else
        tmp = cos(m_1) * exp(-l)
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (l <= 7.2e-31) {
		tmp = Math.exp(((0.25 * Math.pow(m, 2.0)) - (n + l)));
	} else {
		tmp = Math.cos(M) * Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if l <= 7.2e-31:
		tmp = math.exp(((0.25 * math.pow(m, 2.0)) - (n + l)))
	else:
		tmp = math.cos(M) * math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (l <= 7.2e-31)
		tmp = exp(Float64(Float64(0.25 * (m ^ 2.0)) - Float64(n + l)));
	else
		tmp = Float64(cos(M) * exp(Float64(-l)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (l <= 7.2e-31)
		tmp = exp(((0.25 * (m ^ 2.0)) - (n + l)));
	else
		tmp = cos(M) * exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[l, 7.2e-31], N[Exp[N[(N[(0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision] - N[(n + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 7.2 \cdot 10^{-31}:\\
\;\;\;\;e^{0.25 \cdot {m}^{2} - \left(n + \ell\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 7.20000000000000007e-31

    1. Initial program 72.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. Applied egg-rr10.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)} - 1} \]
    3. Step-by-step derivation
      1. expm1-def10.6%

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

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

        \[\leadsto \cos \color{blue}{\left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 - M\right)} \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)} \]
      4. associate-*r*12.1%

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

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

        \[\leadsto \cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(\ell - \left(m - n\right)\right)}} \]
      7. associate--r-12.1%

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
    6. Step-by-step derivation
      1. cos-neg12.1%

        \[\leadsto \color{blue}{\cos M} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
    7. Simplified12.1%

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

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

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

    if 7.20000000000000007e-31 < l

    1. Initial program 83.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. Applied egg-rr30.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)} - 1} \]
    3. Step-by-step derivation
      1. expm1-def30.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)\right)} \]
      2. expm1-log1p30.8%

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

        \[\leadsto \cos \color{blue}{\left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 - M\right)} \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)} \]
      4. associate-*r*30.8%

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

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

        \[\leadsto \cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(\ell - \left(m - n\right)\right)}} \]
      7. associate--r-30.8%

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
    6. Step-by-step derivation
      1. cos-neg30.7%

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

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

      \[\leadsto \color{blue}{\cos M \cdot e^{{\left(0.5 \cdot n - M\right)}^{2} - \left(\ell + n\right)}} \]
    9. Step-by-step derivation
      1. *-commutative40.5%

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

        \[\leadsto \cos M \cdot e^{{\left(n \cdot 0.5 - M\right)}^{2} - \color{blue}{\left(n + \ell\right)}} \]
    10. Simplified40.5%

      \[\leadsto \color{blue}{\cos M \cdot e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)}} \]
    11. Taylor expanded in l around inf 91.6%

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    12. Step-by-step derivation
      1. mul-1-neg91.6%

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    13. Simplified91.6%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification45.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 7.2 \cdot 10^{-31}:\\ \;\;\;\;e^{0.25 \cdot {m}^{2} - \left(n + \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]

Alternative 6: 35.7% accurate, 2.1× speedup?

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

\\
\cos M \cdot e^{-\ell}
\end{array}
Derivation
  1. Initial program 76.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. Applied egg-rr16.9%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)} - 1} \]
  3. Step-by-step derivation
    1. expm1-def16.9%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)\right)} \]
    2. expm1-log1p18.0%

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

      \[\leadsto \cos \color{blue}{\left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 - M\right)} \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)} \]
    4. associate-*r*18.0%

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

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

      \[\leadsto \cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(\ell - \left(m - n\right)\right)}} \]
    7. associate--r-18.0%

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

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

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
  6. Step-by-step derivation
    1. cos-neg18.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
  7. Simplified18.0%

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

    \[\leadsto \color{blue}{\cos M \cdot e^{{\left(0.5 \cdot n - M\right)}^{2} - \left(\ell + n\right)}} \]
  9. Step-by-step derivation
    1. *-commutative21.2%

      \[\leadsto \cos M \cdot e^{{\left(\color{blue}{n \cdot 0.5} - M\right)}^{2} - \left(\ell + n\right)} \]
    2. +-commutative21.2%

      \[\leadsto \cos M \cdot e^{{\left(n \cdot 0.5 - M\right)}^{2} - \color{blue}{\left(n + \ell\right)}} \]
  10. Simplified21.2%

    \[\leadsto \color{blue}{\cos M \cdot e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)}} \]
  11. Taylor expanded in l around inf 38.0%

    \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  12. Step-by-step derivation
    1. mul-1-neg38.0%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  13. Simplified38.0%

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  14. Final simplification38.0%

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

Alternative 7: 20.0% accurate, 3.7× speedup?

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

\\
e^{\left(m + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right) - \left(n + \ell\right)}
\end{array}
Derivation
  1. Initial program 76.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. Applied egg-rr16.9%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)} - 1} \]
  3. Step-by-step derivation
    1. expm1-def16.9%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\mathsf{fma}\left(K \cdot \left(m + n\right), 0.5, -M\right)\right) \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)}\right)\right)} \]
    2. expm1-log1p18.0%

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

      \[\leadsto \cos \color{blue}{\left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 - M\right)} \cdot e^{\left(m - n\right) + \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right)} \]
    4. associate-*r*18.0%

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

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

      \[\leadsto \cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\color{blue}{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(\ell - \left(m - n\right)\right)}} \]
    7. associate--r-18.0%

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

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

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
  6. Step-by-step derivation
    1. cos-neg18.0%

      \[\leadsto \color{blue}{\cos M} \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \left(n + \left(\ell - m\right)\right)} \]
  7. Simplified18.0%

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

    \[\leadsto \color{blue}{e^{\left(m + 0.25 \cdot {\left(m + n\right)}^{2}\right) - \left(\ell + n\right)}} \]
  9. Step-by-step derivation
    1. pow222.7%

      \[\leadsto e^{\left(m + 0.25 \cdot \color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)}\right) - \left(\ell + n\right)} \]
  10. Applied egg-rr22.7%

    \[\leadsto e^{\left(m + 0.25 \cdot \color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)}\right) - \left(\ell + n\right)} \]
  11. Final simplification22.7%

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

Reproduce

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