Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.8% → 96.7%
Time: 21.9s
Alternatives: 6
Speedup: 1.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: 75.8% 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} \\ \frac{\cos \left(-M\right)}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|n - m\right|\right)}} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (/
  (cos (- M))
  (exp (+ (pow (- (/ (+ m n) 2.0) M) 2.0) (- l (fabs (- n m)))))))
double code(double K, double m, double n, double M, double l) {
	return cos(-M) / exp((pow((((m + n) / 2.0) - M), 2.0) + (l - fabs((n - m)))));
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = cos(-m_1) / exp((((((m + n) / 2.0d0) - m_1) ** 2.0d0) + (l - abs((n - m)))))
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(-M) / Math.exp((Math.pow((((m + n) / 2.0) - M), 2.0) + (l - Math.abs((n - m)))));
}
def code(K, m, n, M, l):
	return math.cos(-M) / math.exp((math.pow((((m + n) / 2.0) - M), 2.0) + (l - math.fabs((n - m)))))
function code(K, m, n, M, l)
	return Float64(cos(Float64(-M)) / exp(Float64((Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0) + Float64(l - abs(Float64(n - m))))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos(-M) / exp((((((m + n) / 2.0) - M) ^ 2.0) + (l - abs((n - m)))));
end
code[K_, m_, n_, M_, l_] := N[(N[Cos[(-M)], $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[(n - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

Alternative 2: 73.5% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|n - m\right|\\ t_1 := \frac{\cos M}{e^{\left(\ell - t_0\right) + M \cdot M}}\\ t_2 := e^{t_0 - \left(\ell + 0.25 \cdot \left(m \cdot m\right)\right)}\\ \mathbf{if}\;n \leq -1.02 \cdot 10^{-179}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;n \leq -3.1 \cdot 10^{-257}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 1.15 \cdot 10^{-126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;n \leq 52:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- n m)))
        (t_1 (/ (cos M) (exp (+ (- l t_0) (* M M)))))
        (t_2 (exp (- t_0 (+ l (* 0.25 (* m m)))))))
   (if (<= n -1.02e-179)
     t_2
     (if (<= n -3.1e-257)
       t_1
       (if (<= n 1.15e-126)
         t_2
         (if (<= n 52.0) t_1 (/ (cos M) (exp (* 0.25 (* n n))))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((n - m));
	double t_1 = cos(M) / exp(((l - t_0) + (M * M)));
	double t_2 = exp((t_0 - (l + (0.25 * (m * m)))));
	double tmp;
	if (n <= -1.02e-179) {
		tmp = t_2;
	} else if (n <= -3.1e-257) {
		tmp = t_1;
	} else if (n <= 1.15e-126) {
		tmp = t_2;
	} else if (n <= 52.0) {
		tmp = t_1;
	} else {
		tmp = cos(M) / exp((0.25 * (n * n)));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = abs((n - m))
    t_1 = cos(m_1) / exp(((l - t_0) + (m_1 * m_1)))
    t_2 = exp((t_0 - (l + (0.25d0 * (m * m)))))
    if (n <= (-1.02d-179)) then
        tmp = t_2
    else if (n <= (-3.1d-257)) then
        tmp = t_1
    else if (n <= 1.15d-126) then
        tmp = t_2
    else if (n <= 52.0d0) then
        tmp = t_1
    else
        tmp = cos(m_1) / exp((0.25d0 * (n * n)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.abs((n - m));
	double t_1 = Math.cos(M) / Math.exp(((l - t_0) + (M * M)));
	double t_2 = Math.exp((t_0 - (l + (0.25 * (m * m)))));
	double tmp;
	if (n <= -1.02e-179) {
		tmp = t_2;
	} else if (n <= -3.1e-257) {
		tmp = t_1;
	} else if (n <= 1.15e-126) {
		tmp = t_2;
	} else if (n <= 52.0) {
		tmp = t_1;
	} else {
		tmp = Math.cos(M) / Math.exp((0.25 * (n * n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((n - m))
	t_1 = math.cos(M) / math.exp(((l - t_0) + (M * M)))
	t_2 = math.exp((t_0 - (l + (0.25 * (m * m)))))
	tmp = 0
	if n <= -1.02e-179:
		tmp = t_2
	elif n <= -3.1e-257:
		tmp = t_1
	elif n <= 1.15e-126:
		tmp = t_2
	elif n <= 52.0:
		tmp = t_1
	else:
		tmp = math.cos(M) / math.exp((0.25 * (n * n)))
	return tmp
function code(K, m, n, M, l)
	t_0 = abs(Float64(n - m))
	t_1 = Float64(cos(M) / exp(Float64(Float64(l - t_0) + Float64(M * M))))
	t_2 = exp(Float64(t_0 - Float64(l + Float64(0.25 * Float64(m * m)))))
	tmp = 0.0
	if (n <= -1.02e-179)
		tmp = t_2;
	elseif (n <= -3.1e-257)
		tmp = t_1;
	elseif (n <= 1.15e-126)
		tmp = t_2;
	elseif (n <= 52.0)
		tmp = t_1;
	else
		tmp = Float64(cos(M) / exp(Float64(0.25 * Float64(n * n))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((n - m));
	t_1 = cos(M) / exp(((l - t_0) + (M * M)));
	t_2 = exp((t_0 - (l + (0.25 * (m * m)))));
	tmp = 0.0;
	if (n <= -1.02e-179)
		tmp = t_2;
	elseif (n <= -3.1e-257)
		tmp = t_1;
	elseif (n <= 1.15e-126)
		tmp = t_2;
	elseif (n <= 52.0)
		tmp = t_1;
	else
		tmp = cos(M) / exp((0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(N[(l - t$95$0), $MachinePrecision] + N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Exp[N[(t$95$0 - N[(l + N[(0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, -1.02e-179], t$95$2, If[LessEqual[n, -3.1e-257], t$95$1, If[LessEqual[n, 1.15e-126], t$95$2, If[LessEqual[n, 52.0], t$95$1, N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|n - m\right|\\
t_1 := \frac{\cos M}{e^{\left(\ell - t_0\right) + M \cdot M}}\\
t_2 := e^{t_0 - \left(\ell + 0.25 \cdot \left(m \cdot m\right)\right)}\\
\mathbf{if}\;n \leq -1.02 \cdot 10^{-179}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;n \leq -3.1 \cdot 10^{-257}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;n \leq 1.15 \cdot 10^{-126}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;n \leq 52:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -1.02e-179 or -3.10000000000000008e-257 < n < 1.15000000000000005e-126

    1. Initial program 76.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. Simplified76.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{e^{\color{blue}{\left(0.25 \cdot {m}^{2} + \ell\right)} - \left|n + -1 \cdot m\right|}} \]
      4. mul-1-neg67.3%

        \[\leadsto \frac{1}{e^{\left(0.25 \cdot {m}^{2} + \ell\right) - \left|n + \color{blue}{\left(-m\right)}\right|}} \]
      5. sub-neg67.3%

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

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

        \[\leadsto \frac{1}{e^{\color{blue}{{m}^{2} \cdot 0.25} + \left(\ell - \left|n - m\right|\right)}} \]
      8. fma-def67.3%

        \[\leadsto \frac{1}{e^{\color{blue}{\mathsf{fma}\left({m}^{2}, 0.25, \ell - \left|n - m\right|\right)}}} \]
      9. unpow267.3%

        \[\leadsto \frac{1}{e^{\mathsf{fma}\left(\color{blue}{m \cdot m}, 0.25, \ell - \left|n - m\right|\right)}} \]
      10. rem-log-exp67.3%

        \[\leadsto \frac{1}{e^{\color{blue}{\log \left(e^{\mathsf{fma}\left(m \cdot m, 0.25, \ell - \left|n - m\right|\right)}\right)}}} \]
      11. rec-exp67.3%

        \[\leadsto \color{blue}{e^{-\log \left(e^{\mathsf{fma}\left(m \cdot m, 0.25, \ell - \left|n - m\right|\right)}\right)}} \]
      12. rem-log-exp67.3%

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

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

    if -1.02e-179 < n < -3.10000000000000008e-257 or 1.15000000000000005e-126 < n < 52

    1. Initial program 76.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. Simplified76.7%

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

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

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

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

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

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

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

    if 52 < n

    1. Initial program 68.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. Simplified68.1%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot {n}^{2}}}} \]
    10. Step-by-step derivation
      1. unpow298.6%

        \[\leadsto \frac{\cos M}{e^{0.25 \cdot \color{blue}{\left(n \cdot n\right)}}} \]
    11. Simplified98.6%

      \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot \left(n \cdot n\right)}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification77.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -1.02 \cdot 10^{-179}:\\ \;\;\;\;e^{\left|n - m\right| - \left(\ell + 0.25 \cdot \left(m \cdot m\right)\right)}\\ \mathbf{elif}\;n \leq -3.1 \cdot 10^{-257}:\\ \;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|n - m\right|\right) + M \cdot M}}\\ \mathbf{elif}\;n \leq 1.15 \cdot 10^{-126}:\\ \;\;\;\;e^{\left|n - m\right| - \left(\ell + 0.25 \cdot \left(m \cdot m\right)\right)}\\ \mathbf{elif}\;n \leq 52:\\ \;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|n - m\right|\right) + M \cdot M}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \]

Alternative 3: 73.6% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.25 \cdot \left(m \cdot m\right)\\ t_1 := \left|n - m\right|\\ t_2 := \ell - t_1\\ t_3 := \frac{\cos M}{e^{t_2 + M \cdot M}}\\ \mathbf{if}\;n \leq -1.35 \cdot 10^{-179}:\\ \;\;\;\;e^{t_1 - \left(\ell + t_0\right)}\\ \mathbf{elif}\;n \leq -9.5 \cdot 10^{-257}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;n \leq 1.45 \cdot 10^{-126}:\\ \;\;\;\;\frac{\cos M}{e^{t_2 + t_0}}\\ \mathbf{elif}\;n \leq 52:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* 0.25 (* m m)))
        (t_1 (fabs (- n m)))
        (t_2 (- l t_1))
        (t_3 (/ (cos M) (exp (+ t_2 (* M M))))))
   (if (<= n -1.35e-179)
     (exp (- t_1 (+ l t_0)))
     (if (<= n -9.5e-257)
       t_3
       (if (<= n 1.45e-126)
         (/ (cos M) (exp (+ t_2 t_0)))
         (if (<= n 52.0) t_3 (/ (cos M) (exp (* 0.25 (* n n))))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = 0.25 * (m * m);
	double t_1 = fabs((n - m));
	double t_2 = l - t_1;
	double t_3 = cos(M) / exp((t_2 + (M * M)));
	double tmp;
	if (n <= -1.35e-179) {
		tmp = exp((t_1 - (l + t_0)));
	} else if (n <= -9.5e-257) {
		tmp = t_3;
	} else if (n <= 1.45e-126) {
		tmp = cos(M) / exp((t_2 + t_0));
	} else if (n <= 52.0) {
		tmp = t_3;
	} else {
		tmp = cos(M) / exp((0.25 * (n * n)));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = 0.25d0 * (m * m)
    t_1 = abs((n - m))
    t_2 = l - t_1
    t_3 = cos(m_1) / exp((t_2 + (m_1 * m_1)))
    if (n <= (-1.35d-179)) then
        tmp = exp((t_1 - (l + t_0)))
    else if (n <= (-9.5d-257)) then
        tmp = t_3
    else if (n <= 1.45d-126) then
        tmp = cos(m_1) / exp((t_2 + t_0))
    else if (n <= 52.0d0) then
        tmp = t_3
    else
        tmp = cos(m_1) / exp((0.25d0 * (n * n)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = 0.25 * (m * m);
	double t_1 = Math.abs((n - m));
	double t_2 = l - t_1;
	double t_3 = Math.cos(M) / Math.exp((t_2 + (M * M)));
	double tmp;
	if (n <= -1.35e-179) {
		tmp = Math.exp((t_1 - (l + t_0)));
	} else if (n <= -9.5e-257) {
		tmp = t_3;
	} else if (n <= 1.45e-126) {
		tmp = Math.cos(M) / Math.exp((t_2 + t_0));
	} else if (n <= 52.0) {
		tmp = t_3;
	} else {
		tmp = Math.cos(M) / Math.exp((0.25 * (n * n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = 0.25 * (m * m)
	t_1 = math.fabs((n - m))
	t_2 = l - t_1
	t_3 = math.cos(M) / math.exp((t_2 + (M * M)))
	tmp = 0
	if n <= -1.35e-179:
		tmp = math.exp((t_1 - (l + t_0)))
	elif n <= -9.5e-257:
		tmp = t_3
	elif n <= 1.45e-126:
		tmp = math.cos(M) / math.exp((t_2 + t_0))
	elif n <= 52.0:
		tmp = t_3
	else:
		tmp = math.cos(M) / math.exp((0.25 * (n * n)))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(0.25 * Float64(m * m))
	t_1 = abs(Float64(n - m))
	t_2 = Float64(l - t_1)
	t_3 = Float64(cos(M) / exp(Float64(t_2 + Float64(M * M))))
	tmp = 0.0
	if (n <= -1.35e-179)
		tmp = exp(Float64(t_1 - Float64(l + t_0)));
	elseif (n <= -9.5e-257)
		tmp = t_3;
	elseif (n <= 1.45e-126)
		tmp = Float64(cos(M) / exp(Float64(t_2 + t_0)));
	elseif (n <= 52.0)
		tmp = t_3;
	else
		tmp = Float64(cos(M) / exp(Float64(0.25 * Float64(n * n))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = 0.25 * (m * m);
	t_1 = abs((n - m));
	t_2 = l - t_1;
	t_3 = cos(M) / exp((t_2 + (M * M)));
	tmp = 0.0;
	if (n <= -1.35e-179)
		tmp = exp((t_1 - (l + t_0)));
	elseif (n <= -9.5e-257)
		tmp = t_3;
	elseif (n <= 1.45e-126)
		tmp = cos(M) / exp((t_2 + t_0));
	elseif (n <= 52.0)
		tmp = t_3;
	else
		tmp = cos(M) / exp((0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(l - t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(t$95$2 + N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, -1.35e-179], N[Exp[N[(t$95$1 - N[(l + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[n, -9.5e-257], t$95$3, If[LessEqual[n, 1.45e-126], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(t$95$2 + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 52.0], t$95$3, N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.25 \cdot \left(m \cdot m\right)\\
t_1 := \left|n - m\right|\\
t_2 := \ell - t_1\\
t_3 := \frac{\cos M}{e^{t_2 + M \cdot M}}\\
\mathbf{if}\;n \leq -1.35 \cdot 10^{-179}:\\
\;\;\;\;e^{t_1 - \left(\ell + t_0\right)}\\

\mathbf{elif}\;n \leq -9.5 \cdot 10^{-257}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;n \leq 1.45 \cdot 10^{-126}:\\
\;\;\;\;\frac{\cos M}{e^{t_2 + t_0}}\\

\mathbf{elif}\;n \leq 52:\\
\;\;\;\;t_3\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if n < -1.34999999999999994e-179

    1. Initial program 73.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. Simplified73.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{e^{\color{blue}{\mathsf{fma}\left({m}^{2}, 0.25, \ell - \left|n - m\right|\right)}}} \]
      9. unpow256.2%

        \[\leadsto \frac{1}{e^{\mathsf{fma}\left(\color{blue}{m \cdot m}, 0.25, \ell - \left|n - m\right|\right)}} \]
      10. rem-log-exp56.2%

        \[\leadsto \frac{1}{e^{\color{blue}{\log \left(e^{\mathsf{fma}\left(m \cdot m, 0.25, \ell - \left|n - m\right|\right)}\right)}}} \]
      11. rec-exp56.2%

        \[\leadsto \color{blue}{e^{-\log \left(e^{\mathsf{fma}\left(m \cdot m, 0.25, \ell - \left|n - m\right|\right)}\right)}} \]
      12. rem-log-exp56.2%

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

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

    if -1.34999999999999994e-179 < n < -9.49999999999999941e-257 or 1.44999999999999994e-126 < n < 52

    1. Initial program 76.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. Simplified76.7%

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

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

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

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

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

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

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

    if -9.49999999999999941e-257 < n < 1.44999999999999994e-126

    1. Initial program 82.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. Simplified82.2%

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

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

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

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

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

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

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

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

    if 52 < n

    1. Initial program 68.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. Simplified68.1%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot {n}^{2}}}} \]
    10. Step-by-step derivation
      1. unpow298.6%

        \[\leadsto \frac{\cos M}{e^{0.25 \cdot \color{blue}{\left(n \cdot n\right)}}} \]
    11. Simplified98.6%

      \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot \left(n \cdot n\right)}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification77.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -1.35 \cdot 10^{-179}:\\ \;\;\;\;e^{\left|n - m\right| - \left(\ell + 0.25 \cdot \left(m \cdot m\right)\right)}\\ \mathbf{elif}\;n \leq -9.5 \cdot 10^{-257}:\\ \;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|n - m\right|\right) + M \cdot M}}\\ \mathbf{elif}\;n \leq 1.45 \cdot 10^{-126}:\\ \;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|n - m\right|\right) + 0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{elif}\;n \leq 52:\\ \;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|n - m\right|\right) + M \cdot M}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \]

Alternative 4: 74.3% accurate, 2.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 0.419999999999999984

    1. Initial program 76.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. Simplified76.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{e^{\color{blue}{\left(0.25 \cdot {m}^{2} + \ell\right)} - \left|n + -1 \cdot m\right|}} \]
      4. mul-1-neg66.3%

        \[\leadsto \frac{1}{e^{\left(0.25 \cdot {m}^{2} + \ell\right) - \left|n + \color{blue}{\left(-m\right)}\right|}} \]
      5. sub-neg66.3%

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

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

        \[\leadsto \frac{1}{e^{\color{blue}{{m}^{2} \cdot 0.25} + \left(\ell - \left|n - m\right|\right)}} \]
      8. fma-def66.3%

        \[\leadsto \frac{1}{e^{\color{blue}{\mathsf{fma}\left({m}^{2}, 0.25, \ell - \left|n - m\right|\right)}}} \]
      9. unpow266.3%

        \[\leadsto \frac{1}{e^{\mathsf{fma}\left(\color{blue}{m \cdot m}, 0.25, \ell - \left|n - m\right|\right)}} \]
      10. rem-log-exp66.3%

        \[\leadsto \frac{1}{e^{\color{blue}{\log \left(e^{\mathsf{fma}\left(m \cdot m, 0.25, \ell - \left|n - m\right|\right)}\right)}}} \]
      11. rec-exp66.3%

        \[\leadsto \color{blue}{e^{-\log \left(e^{\mathsf{fma}\left(m \cdot m, 0.25, \ell - \left|n - m\right|\right)}\right)}} \]
      12. rem-log-exp66.3%

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

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

    if 0.419999999999999984 < n

    1. Initial program 68.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. Simplified68.1%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot {n}^{2}}}} \]
    10. Step-by-step derivation
      1. unpow298.6%

        \[\leadsto \frac{\cos M}{e^{0.25 \cdot \color{blue}{\left(n \cdot n\right)}}} \]
    11. Simplified98.6%

      \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot \left(n \cdot n\right)}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.0%

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

Alternative 5: 69.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq -54 \lor \neg \left(n \leq 0.42\right):\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (or (<= n -54.0) (not (<= n 0.42)))
   (/ (cos M) (exp (* 0.25 (* n n))))
   (/ (cos M) (exp l))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((n <= -54.0) || !(n <= 0.42)) {
		tmp = cos(M) / exp((0.25 * (n * n)));
	} 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 ((n <= (-54.0d0)) .or. (.not. (n <= 0.42d0))) then
        tmp = cos(m_1) / exp((0.25d0 * (n * n)))
    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 ((n <= -54.0) || !(n <= 0.42)) {
		tmp = Math.cos(M) / Math.exp((0.25 * (n * n)));
	} else {
		tmp = Math.cos(M) / Math.exp(l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if (n <= -54.0) or not (n <= 0.42):
		tmp = math.cos(M) / math.exp((0.25 * (n * n)))
	else:
		tmp = math.cos(M) / math.exp(l)
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if ((n <= -54.0) || !(n <= 0.42))
		tmp = Float64(cos(M) / exp(Float64(0.25 * Float64(n * n))));
	else
		tmp = Float64(cos(M) / exp(l));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if ((n <= -54.0) || ~((n <= 0.42)))
		tmp = cos(M) / exp((0.25 * (n * n)));
	else
		tmp = cos(M) / exp(l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[n, -54.0], N[Not[LessEqual[n, 0.42]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n \leq -54 \lor \neg \left(n \leq 0.42\right):\\
\;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -54 or 0.419999999999999984 < n

    1. Initial program 67.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. Simplified67.2%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot {n}^{2}}}} \]
    10. Step-by-step derivation
      1. unpow297.0%

        \[\leadsto \frac{\cos M}{e^{0.25 \cdot \color{blue}{\left(n \cdot n\right)}}} \]
    11. Simplified97.0%

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

    if -54 < n < 0.419999999999999984

    1. Initial program 81.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. Simplified81.9%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\cos M}{e^{\color{blue}{\ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -54 \lor \neg \left(n \leq 0.42\right):\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \end{array} \]

Alternative 6: 35.3% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \frac{\cos M}{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(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}

\\
\frac{\cos M}{e^{\ell}}
\end{array}
Derivation
  1. Initial program 74.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\cos M}{e^{\color{blue}{\ell}}} \]
  10. Final simplification38.6%

    \[\leadsto \frac{\cos M}{e^{\ell}} \]

Reproduce

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