Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.6% → 96.6%
Time: 24.5s
Alternatives: 11
Speedup: 1.3×

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

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

Initial Program: 75.6% accurate, 1.0× speedup?

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

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

Alternative 1: 96.6% accurate, 1.0× speedup?

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

\\
\cos M \cdot e^{\left|m - n\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}
\end{array}
Derivation
  1. Initial program 79.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. Step-by-step derivation
    1. associate-/l*78.8%

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

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

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

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

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

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

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

Alternative 2: 96.6% accurate, 1.0× speedup?

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

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

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

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

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

Alternative 3: 92.6% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;M \leq -6.5 \cdot 10^{+124} \lor \neg \left(M \leq 1.15 \cdot 10^{+87}\right):\\
\;\;\;\;\frac{\cos M}{e^{\left(\ell - t_0\right) + M \cdot M}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -6.50000000000000008e124 or 1.1500000000000001e87 < M

    1. Initial program 83.5%

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

      \[\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 83.5%

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

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

      \[\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 97.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-neg97.5%

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

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

    if -6.50000000000000008e124 < M < 1.1500000000000001e87

    1. Initial program 77.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. Step-by-step derivation
      1. associate-/l*76.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -6.5 \cdot 10^{+124} \lor \neg \left(M \leq 1.15 \cdot 10^{+87}\right):\\ \;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|m - n\right|\right) + M \cdot M}}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}\\ \end{array} \]

Alternative 4: 68.4% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;n \leq 2.7 \cdot 10^{+17}:\\
\;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|m - n\right|\right) + M \cdot M}}\\

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


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

    1. Initial program 80.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. Step-by-step derivation
      1. associate-/l*80.7%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative45.1%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow245.1%

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
      3. associate-*l*45.1%

        \[\leadsto e^{\color{blue}{m \cdot \left(m \cdot -0.25\right)}} \]
    10. Simplified45.1%

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

    if -3.3e-256 < n < 2.7e17

    1. Initial program 83.1%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Simplified83.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 M around inf 67.1%

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

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

      \[\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 68.2%

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

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

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

    if 2.7e17 < n

    1. Initial program 71.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. Step-by-step derivation
      1. associate-/l*71.2%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative95.0%

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow295.0%

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    10. Simplified95.0%

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

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

Alternative 5: 65.5% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq 1.15 \cdot 10^{-178}:\\
\;\;\;\;\frac{\cos \left(0.5 \cdot \left(m \cdot K\right) - M\right)}{e^{M \cdot M}}\\

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


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

    1. Initial program 71.4%

      \[\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. Step-by-step derivation
      1. associate-/l*71.4%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative96.9%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow296.9%

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
      3. associate-*l*96.9%

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

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

    if -116000 < m < 1.14999999999999997e-178

    1. Initial program 83.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. Simplified83.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 M around inf 67.1%

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

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

      \[\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 n around 0 69.8%

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

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

        \[\leadsto \frac{\cos \left(0.5 \cdot \left(K \cdot m\right) - M\right)}{e^{\color{blue}{M \cdot M}}} \]
    9. Simplified57.3%

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

    if 1.14999999999999997e-178 < m

    1. Initial program 80.4%

      \[\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. Step-by-step derivation
      1. associate-/l*79.4%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative48.6%

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow248.6%

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    10. Simplified48.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -116000:\\ \;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{elif}\;m \leq 1.15 \cdot 10^{-178}:\\ \;\;\;\;\frac{\cos \left(0.5 \cdot \left(m \cdot K\right) - M\right)}{e^{M \cdot M}}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]

Alternative 6: 59.3% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq 2.05 \cdot 10^{-227}:\\
\;\;\;\;\frac{\cos \left(K \cdot \left(n \cdot 0.5\right) - M\right)}{e^{\ell}}\\

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


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

    1. Initial program 71.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*71.0%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative98.4%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow298.4%

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
      3. associate-*l*98.4%

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

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

    if -1.28e20 < m < 2.05000000000000005e-227

    1. Initial program 83.1%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Simplified83.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 M around inf 66.7%

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

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

      \[\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 l around inf 44.2%

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

      \[\leadsto \frac{\color{blue}{\cos \left(0.5 \cdot \left(n \cdot K\right) - M\right)}}{e^{\ell}} \]
    8. Step-by-step derivation
      1. associate-*r*43.9%

        \[\leadsto \frac{\cos \left(\color{blue}{\left(0.5 \cdot n\right) \cdot K} - M\right)}{e^{\ell}} \]
      2. *-commutative43.9%

        \[\leadsto \frac{\cos \left(\color{blue}{\left(n \cdot 0.5\right)} \cdot K - M\right)}{e^{\ell}} \]
    9. Simplified43.9%

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

    if 2.05000000000000005e-227 < m

    1. Initial program 80.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. Step-by-step derivation
      1. associate-/l*80.0%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative48.8%

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow248.8%

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    10. Simplified48.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1.28 \cdot 10^{+20}:\\ \;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{elif}\;m \leq 2.05 \cdot 10^{-227}:\\ \;\;\;\;\frac{\cos \left(K \cdot \left(n \cdot 0.5\right) - M\right)}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]

Alternative 7: 60.6% accurate, 2.1× speedup?

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

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

\mathbf{elif}\;m \leq 7.6 \cdot 10^{-227}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

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


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

    1. Initial program 71.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*71.0%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative98.4%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow298.4%

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
      3. associate-*l*98.4%

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

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

    if -1.28e20 < m < 7.60000000000000019e-227

    1. Initial program 83.1%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Simplified83.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 M around inf 66.7%

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

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

      \[\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 l around inf 44.2%

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

      \[\leadsto \color{blue}{\frac{\cos \left(-M\right)}{e^{\ell}}} \]
    8. Step-by-step derivation
      1. cos-neg47.9%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    9. Simplified47.9%

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

    if 7.60000000000000019e-227 < m

    1. Initial program 80.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. Step-by-step derivation
      1. associate-/l*80.0%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative48.8%

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow248.8%

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    10. Simplified48.8%

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

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

Alternative 8: 68.4% accurate, 3.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -1.28 \cdot 10^{+20} \lor \neg \left(m \leq 3.2 \cdot 10^{-48}\right):\\
\;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -1.28e20 or 3.1999999999999998e-48 < m

    1. Initial program 74.4%

      \[\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. Step-by-step derivation
      1. associate-/l*73.6%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative88.3%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow288.3%

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
      3. associate-*l*88.3%

        \[\leadsto e^{\color{blue}{m \cdot \left(m \cdot -0.25\right)}} \]
    10. Simplified88.3%

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

    if -1.28e20 < m < 3.1999999999999998e-48

    1. Initial program 83.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. Step-by-step derivation
      1. associate-/l*83.7%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    9. Step-by-step derivation
      1. neg-mul-146.5%

        \[\leadsto e^{\color{blue}{-\ell}} \]
    10. Simplified46.5%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1.28 \cdot 10^{+20} \lor \neg \left(m \leq 3.2 \cdot 10^{-48}\right):\\ \;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 9: 60.6% accurate, 3.9× speedup?

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

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

\mathbf{elif}\;m \leq 8.4 \cdot 10^{-237}:\\
\;\;\;\;e^{-\ell}\\

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


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

    1. Initial program 71.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*71.0%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative98.4%

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow298.4%

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
      3. associate-*l*98.4%

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

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

    if -1.28e20 < m < 8.4000000000000005e-237

    1. Initial program 82.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. Step-by-step derivation
      1. associate-/l*82.6%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    9. Step-by-step derivation
      1. neg-mul-145.6%

        \[\leadsto e^{\color{blue}{-\ell}} \]
    10. Simplified45.6%

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

    if 8.4000000000000005e-237 < m

    1. Initial program 81.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. Step-by-step derivation
      1. associate-/l*80.4%

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative49.4%

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow249.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1.28 \cdot 10^{+20}:\\ \;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{elif}\;m \leq 8.4 \cdot 10^{-237}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]

Alternative 10: 35.6% accurate, 4.2× speedup?

\[\begin{array}{l} \\ e^{-\ell} \end{array} \]
(FPCore (K m n M l) :precision binary64 (exp (- l)))
double code(double K, double m, double n, double M, double l) {
	return exp(-l);
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = exp(-l)
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.exp(-l);
}
def code(K, m, n, M, l):
	return math.exp(-l)
function code(K, m, n, M, l)
	return exp(Float64(-l))
end
function tmp = code(K, m, n, M, l)
	tmp = exp(-l);
end
code[K_, m_, n_, M_, l_] := N[Exp[(-l)], $MachinePrecision]
\begin{array}{l}

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 79.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. Step-by-step derivation
    1. associate-/l*78.8%

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

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

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

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

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

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

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

    \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
  9. Step-by-step derivation
    1. neg-mul-139.5%

      \[\leadsto e^{\color{blue}{-\ell}} \]
  10. Simplified39.5%

    \[\leadsto e^{\color{blue}{-\ell}} \]
  11. Final simplification39.5%

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

Alternative 11: 6.7% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \cos M \end{array} \]
(FPCore (K m n M l) :precision binary64 (cos M))
double code(double K, double m, double n, double M, double l) {
	return cos(M);
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = cos(m_1)
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M);
}
def code(K, m, n, M, l):
	return math.cos(M)
function code(K, m, n, M, l)
	return cos(M)
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M);
end
code[K_, m_, n_, M_, l_] := N[Cos[M], $MachinePrecision]
\begin{array}{l}

\\
\cos M
\end{array}
Derivation
  1. Initial program 79.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. Simplified79.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 54.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. unpow254.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. Simplified54.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 l around inf 35.7%

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

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  9. Step-by-step derivation
    1. cos-neg8.4%

      \[\leadsto \color{blue}{\cos M} \]
  10. Simplified8.4%

    \[\leadsto \color{blue}{\cos M} \]
  11. Final simplification8.4%

    \[\leadsto \cos M \]

Reproduce

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