Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.2% → 96.7%
Time: 17.9s
Alternatives: 6
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 6 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.2% 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, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 2: 94.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right|\\ \mathbf{if}\;M \leq -6 \cdot 10^{-41} \lor \neg \left(M \leq 1.9 \cdot 10^{+63}\right):\\ \;\;\;\;\cos M \cdot e^{t_0 - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- m n))))
   (if (or (<= M -6e-41) (not (<= M 1.9e+63)))
     (* (cos M) (exp (- t_0 (pow (- (* (+ m n) 0.5) M) 2.0))))
     (exp (- t_0 (+ l (* 0.25 (* (+ m n) (+ m n)))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n));
	double tmp;
	if ((M <= -6e-41) || !(M <= 1.9e+63)) {
		tmp = cos(M) * exp((t_0 - pow((((m + n) * 0.5) - M), 2.0)));
	} else {
		tmp = exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: tmp
    t_0 = abs((m - n))
    if ((m_1 <= (-6d-41)) .or. (.not. (m_1 <= 1.9d+63))) then
        tmp = cos(m_1) * exp((t_0 - ((((m + n) * 0.5d0) - m_1) ** 2.0d0)))
    else
        tmp = exp((t_0 - (l + (0.25d0 * ((m + n) * (m + n))))))
    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((m - n));
	double tmp;
	if ((M <= -6e-41) || !(M <= 1.9e+63)) {
		tmp = Math.cos(M) * Math.exp((t_0 - Math.pow((((m + n) * 0.5) - M), 2.0)));
	} else {
		tmp = Math.exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n))
	tmp = 0
	if (M <= -6e-41) or not (M <= 1.9e+63):
		tmp = math.cos(M) * math.exp((t_0 - math.pow((((m + n) * 0.5) - M), 2.0)))
	else:
		tmp = math.exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))))
	return tmp
function code(K, m, n, M, l)
	t_0 = abs(Float64(m - n))
	tmp = 0.0
	if ((M <= -6e-41) || !(M <= 1.9e+63))
		tmp = Float64(cos(M) * exp(Float64(t_0 - (Float64(Float64(Float64(m + n) * 0.5) - M) ^ 2.0))));
	else
		tmp = exp(Float64(t_0 - Float64(l + Float64(0.25 * Float64(Float64(m + n) * Float64(m + n))))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((m - n));
	tmp = 0.0;
	if ((M <= -6e-41) || ~((M <= 1.9e+63)))
		tmp = cos(M) * exp((t_0 - ((((m + n) * 0.5) - M) ^ 2.0)));
	else
		tmp = exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[M, -6e-41], N[Not[LessEqual[M, 1.9e+63]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(t$95$0 - N[Power[N[(N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;M \leq -6 \cdot 10^{-41} \lor \neg \left(M \leq 1.9 \cdot 10^{+63}\right):\\
\;\;\;\;\cos M \cdot e^{t_0 - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -5.99999999999999978e-41 or 1.9000000000000001e63 < M

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|m - n\right| - \color{blue}{\left(\left(m + n\right) \cdot 0.5 - M\right) \cdot \left(\left(m + n\right) \cdot 0.5 - M\right)}} \]
      3. unpow296.9%

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

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

    if -5.99999999999999978e-41 < M < 1.9000000000000001e63

    1. Initial program 75.9%

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

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

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

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

      \[\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. unpow293.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -6 \cdot 10^{-41} \lor \neg \left(M \leq 1.9 \cdot 10^{+63}\right):\\ \;\;\;\;\cos M \cdot e^{\left|m - n\right| - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}\\ \end{array} \]

Alternative 3: 88.5% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right|\\ \mathbf{if}\;n \leq 2.9 \cdot 10^{-251} \lor \neg \left(n \leq 900\right):\\ \;\;\;\;e^{t_0 - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\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)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- m n))))
   (if (or (<= n 2.9e-251) (not (<= n 900.0)))
     (exp (- t_0 (+ l (* 0.25 (* (+ m n) (+ m n))))))
     (*
      (cos (- (/ (* (+ m n) K) 2.0) M))
      (exp (+ (* (- (* m 0.5) M) (- (- M (* m 0.5)) n)) (- t_0 l)))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n));
	double tmp;
	if ((n <= 2.9e-251) || !(n <= 900.0)) {
		tmp = exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	} else {
		tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) + (t_0 - 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) :: t_0
    real(8) :: tmp
    t_0 = abs((m - n))
    if ((n <= 2.9d-251) .or. (.not. (n <= 900.0d0))) then
        tmp = exp((t_0 - (l + (0.25d0 * ((m + n) * (m + n))))))
    else
        tmp = cos(((((m + n) * k) / 2.0d0) - m_1)) * exp(((((m * 0.5d0) - m_1) * ((m_1 - (m * 0.5d0)) - n)) + (t_0 - l)))
    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((m - n));
	double tmp;
	if ((n <= 2.9e-251) || !(n <= 900.0)) {
		tmp = Math.exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	} else {
		tmp = Math.cos(((((m + n) * K) / 2.0) - M)) * Math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) + (t_0 - l)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n))
	tmp = 0
	if (n <= 2.9e-251) or not (n <= 900.0):
		tmp = math.exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))))
	else:
		tmp = math.cos(((((m + n) * K) / 2.0) - M)) * math.exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) + (t_0 - l)))
	return tmp
function code(K, m, n, M, l)
	t_0 = abs(Float64(m - n))
	tmp = 0.0
	if ((n <= 2.9e-251) || !(n <= 900.0))
		tmp = exp(Float64(t_0 - Float64(l + Float64(0.25 * Float64(Float64(m + n) * Float64(m + n))))));
	else
		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))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((m - n));
	tmp = 0.0;
	if ((n <= 2.9e-251) || ~((n <= 900.0)))
		tmp = exp((t_0 - (l + (0.25 * ((m + n) * (m + n))))));
	else
		tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((((m * 0.5) - M) * ((M - (m * 0.5)) - n)) + (t_0 - l)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[n, 2.9e-251], N[Not[LessEqual[n, 900.0]], $MachinePrecision]], 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], 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]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\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)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 2.9000000000000001e-251 or 900 < n

    1. Initial program 74.6%

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

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

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. Taylor expanded in M around 0 89.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. unpow289.6%

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

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

    if 2.9000000000000001e-251 < n < 900

    1. Initial program 91.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. Taylor expanded in n around 0 91.7%

      \[\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. +-commutative91.7%

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

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

        \[\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. *-commutative91.7%

        \[\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. *-commutative91.7%

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

      \[\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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 2.9 \cdot 10^{-251} \lor \neg \left(n \leq 900\right):\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\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|m - n\right| - \ell\right)}\\ \end{array} \]

Alternative 4: 88.8% accurate, 1.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 6.0000000000000005e126

    1. Initial program 78.1%

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

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

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. Taylor expanded in M around 0 89.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. unpow289.0%

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

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

    if 6.0000000000000005e126 < M

    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 K around 0 100.0%

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(-1 \cdot M\right) \cdot \left(m + n\right)} + {M}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. neg-mul-154.8%

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\left(-M\right) \cdot \left(m + n\right) + \color{blue}{\left(-M\right) \cdot \left(-M\right)}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      5. distribute-lft-out93.0%

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{\left(-M\right) \cdot \left(\left(m + n\right) + \left(-M\right)\right)}\right) - \left(\ell - \left|m - n\right|\right)} \]
      6. unsub-neg93.0%

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left|n - m\right| - \left(\ell + \color{blue}{\left(-M \cdot \left(m - M\right)\right)}\right)} \]
      3. unsub-neg90.6%

        \[\leadsto \cos M \cdot e^{\left|n - m\right| - \color{blue}{\left(\ell - M \cdot \left(m - M\right)\right)}} \]
    10. Simplified90.6%

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

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

Alternative 5: 86.8% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

Alternative 6: 24.2% accurate, 2.1× speedup?

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

\\
e^{\left|m - n\right| - \ell}
\end{array}
Derivation
  1. Initial program 77.8%

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(-1 \cdot M\right) \cdot \left(m + n\right)} + {M}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. neg-mul-146.6%

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

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

      \[\leadsto \cos M \cdot e^{\left(-\left(\left(-M\right) \cdot \left(m + n\right) + \color{blue}{\left(-M\right) \cdot \left(-M\right)}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    5. distribute-lft-out53.7%

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

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

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

    \[\leadsto \color{blue}{e^{\left|m - n\right| - \ell}} \]
  9. Step-by-step derivation
    1. fabs-sub27.0%

      \[\leadsto e^{\color{blue}{\left|n - m\right|} - \ell} \]
    2. sub-neg27.0%

      \[\leadsto e^{\left|\color{blue}{n + \left(-m\right)}\right| - \ell} \]
    3. mul-1-neg27.0%

      \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \ell} \]
    4. fabs-neg27.0%

      \[\leadsto e^{\color{blue}{\left|-\left(n + -1 \cdot m\right)\right|} - \ell} \]
    5. fabs-neg27.0%

      \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \ell} \]
    6. mul-1-neg27.0%

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

      \[\leadsto e^{\left|\color{blue}{n - m}\right| - \ell} \]
  10. Simplified27.0%

    \[\leadsto \color{blue}{e^{\left|n - m\right| - \ell}} \]
  11. Final simplification27.0%

    \[\leadsto e^{\left|m - n\right| - \ell} \]

Reproduce

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