Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.9% → 96.7%
Time: 14.3s
Alternatives: 9
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 9 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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 96.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 2: 94.7% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -1.4 \cdot 10^{+31} \lor \neg \left(M \leq 2.2 \cdot 10^{-11}\right):\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{\left|m - n\right| - \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 < -1.40000000000000008e31 or 2.2000000000000002e-11 < M

    1. Initial program 82.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. Taylor expanded in K around 0 98.5%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    6. Step-by-step derivation
      1. mul-1-neg97.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
      2. unpow297.7%

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in97.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    7. Simplified97.7%

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

    if -1.40000000000000008e31 < M < 2.2000000000000002e-11

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

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

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

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

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

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

Alternative 3: 65.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{-M \cdot M}\\ \mathbf{if}\;n \leq 1.65 \cdot 10^{-280}:\\ \;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{elif}\;n \leq 3.2 \cdot 10^{-154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 1.02 \cdot 10^{-109}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos M) (exp (- (* M M))))))
   (if (<= n 1.65e-280)
     (exp (* m (* m -0.25)))
     (if (<= n 3.2e-154)
       t_0
       (if (<= n 1.02e-109)
         (* (cos M) (exp (- l)))
         (if (<= n 54.0) t_0 (exp (* (* n n) -0.25))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp(-(M * M));
	double tmp;
	if (n <= 1.65e-280) {
		tmp = exp((m * (m * -0.25)));
	} else if (n <= 3.2e-154) {
		tmp = t_0;
	} else if (n <= 1.02e-109) {
		tmp = cos(M) * exp(-l);
	} else if (n <= 54.0) {
		tmp = t_0;
	} else {
		tmp = exp(((n * n) * -0.25));
	}
	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 = cos(m_1) * exp(-(m_1 * m_1))
    if (n <= 1.65d-280) then
        tmp = exp((m * (m * (-0.25d0))))
    else if (n <= 3.2d-154) then
        tmp = t_0
    else if (n <= 1.02d-109) then
        tmp = cos(m_1) * exp(-l)
    else if (n <= 54.0d0) then
        tmp = t_0
    else
        tmp = exp(((n * n) * (-0.25d0)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.cos(M) * Math.exp(-(M * M));
	double tmp;
	if (n <= 1.65e-280) {
		tmp = Math.exp((m * (m * -0.25)));
	} else if (n <= 3.2e-154) {
		tmp = t_0;
	} else if (n <= 1.02e-109) {
		tmp = Math.cos(M) * Math.exp(-l);
	} else if (n <= 54.0) {
		tmp = t_0;
	} else {
		tmp = Math.exp(((n * n) * -0.25));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(M) * math.exp(-(M * M))
	tmp = 0
	if n <= 1.65e-280:
		tmp = math.exp((m * (m * -0.25)))
	elif n <= 3.2e-154:
		tmp = t_0
	elif n <= 1.02e-109:
		tmp = math.cos(M) * math.exp(-l)
	elif n <= 54.0:
		tmp = t_0
	else:
		tmp = math.exp(((n * n) * -0.25))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) * exp(Float64(-Float64(M * M))))
	tmp = 0.0
	if (n <= 1.65e-280)
		tmp = exp(Float64(m * Float64(m * -0.25)));
	elseif (n <= 3.2e-154)
		tmp = t_0;
	elseif (n <= 1.02e-109)
		tmp = Float64(cos(M) * exp(Float64(-l)));
	elseif (n <= 54.0)
		tmp = t_0;
	else
		tmp = exp(Float64(Float64(n * n) * -0.25));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = cos(M) * exp(-(M * M));
	tmp = 0.0;
	if (n <= 1.65e-280)
		tmp = exp((m * (m * -0.25)));
	elseif (n <= 3.2e-154)
		tmp = t_0;
	elseif (n <= 1.02e-109)
		tmp = cos(M) * exp(-l);
	elseif (n <= 54.0)
		tmp = t_0;
	else
		tmp = exp(((n * n) * -0.25));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[(M * M), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, 1.65e-280], N[Exp[N[(m * N[(m * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[n, 3.2e-154], t$95$0, If[LessEqual[n, 1.02e-109], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 54.0], t$95$0, N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{-M \cdot M}\\
\mathbf{if}\;n \leq 1.65 \cdot 10^{-280}:\\
\;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\

\mathbf{elif}\;n \leq 3.2 \cdot 10^{-154}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 1.02 \cdot 10^{-109}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 82.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. Taylor expanded in K around 0 97.2%

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{m \cdot \left(m \cdot -0.25\right)}} \]
    8. Simplified60.7%

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

    if 1.64999999999999995e-280 < n < 3.20000000000000005e-154 or 1.02e-109 < n < 54

    1. Initial program 88.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. Taylor expanded in K around 0 97.0%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    6. Step-by-step derivation
      1. mul-1-neg68.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
      2. unpow268.5%

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in68.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    7. Simplified68.5%

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

    if 3.20000000000000005e-154 < n < 1.02e-109

    1. Initial program 80.0%

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

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

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

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

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

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

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

    if 54 < n

    1. Initial program 70.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 1.65 \cdot 10^{-280}:\\ \;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{elif}\;n \leq 3.2 \cdot 10^{-154}:\\ \;\;\;\;\cos M \cdot e^{-M \cdot M}\\ \mathbf{elif}\;n \leq 1.02 \cdot 10^{-109}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;\cos M \cdot e^{-M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]

Alternative 4: 64.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;n \leq 4.4 \cdot 10^{-274}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;n \leq 3.5 \cdot 10^{-154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 1.15 \cdot 10^{-110}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos M) (exp (* M (- M))))))
   (if (<= n 4.4e-274)
     (* (cos M) (exp (* -0.25 (* m m))))
     (if (<= n 3.5e-154)
       t_0
       (if (<= n 1.15e-110)
         (* (cos M) (exp (- l)))
         (if (<= n 54.0) t_0 (exp (* (* n n) -0.25))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp((M * -M));
	double tmp;
	if (n <= 4.4e-274) {
		tmp = cos(M) * exp((-0.25 * (m * m)));
	} else if (n <= 3.5e-154) {
		tmp = t_0;
	} else if (n <= 1.15e-110) {
		tmp = cos(M) * exp(-l);
	} else if (n <= 54.0) {
		tmp = t_0;
	} else {
		tmp = exp(((n * n) * -0.25));
	}
	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 = cos(m_1) * exp((m_1 * -m_1))
    if (n <= 4.4d-274) then
        tmp = cos(m_1) * exp(((-0.25d0) * (m * m)))
    else if (n <= 3.5d-154) then
        tmp = t_0
    else if (n <= 1.15d-110) then
        tmp = cos(m_1) * exp(-l)
    else if (n <= 54.0d0) then
        tmp = t_0
    else
        tmp = exp(((n * n) * (-0.25d0)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.cos(M) * Math.exp((M * -M));
	double tmp;
	if (n <= 4.4e-274) {
		tmp = Math.cos(M) * Math.exp((-0.25 * (m * m)));
	} else if (n <= 3.5e-154) {
		tmp = t_0;
	} else if (n <= 1.15e-110) {
		tmp = Math.cos(M) * Math.exp(-l);
	} else if (n <= 54.0) {
		tmp = t_0;
	} else {
		tmp = Math.exp(((n * n) * -0.25));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(M) * math.exp((M * -M))
	tmp = 0
	if n <= 4.4e-274:
		tmp = math.cos(M) * math.exp((-0.25 * (m * m)))
	elif n <= 3.5e-154:
		tmp = t_0
	elif n <= 1.15e-110:
		tmp = math.cos(M) * math.exp(-l)
	elif n <= 54.0:
		tmp = t_0
	else:
		tmp = math.exp(((n * n) * -0.25))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) * exp(Float64(M * Float64(-M))))
	tmp = 0.0
	if (n <= 4.4e-274)
		tmp = Float64(cos(M) * exp(Float64(-0.25 * Float64(m * m))));
	elseif (n <= 3.5e-154)
		tmp = t_0;
	elseif (n <= 1.15e-110)
		tmp = Float64(cos(M) * exp(Float64(-l)));
	elseif (n <= 54.0)
		tmp = t_0;
	else
		tmp = exp(Float64(Float64(n * n) * -0.25));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = cos(M) * exp((M * -M));
	tmp = 0.0;
	if (n <= 4.4e-274)
		tmp = cos(M) * exp((-0.25 * (m * m)));
	elseif (n <= 3.5e-154)
		tmp = t_0;
	elseif (n <= 1.15e-110)
		tmp = cos(M) * exp(-l);
	elseif (n <= 54.0)
		tmp = t_0;
	else
		tmp = exp(((n * n) * -0.25));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, 4.4e-274], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 3.5e-154], t$95$0, If[LessEqual[n, 1.15e-110], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 54.0], t$95$0, N[Exp[N[(N[(n * n), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{M \cdot \left(-M\right)}\\
\mathbf{if}\;n \leq 4.4 \cdot 10^{-274}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\

\mathbf{elif}\;n \leq 3.5 \cdot 10^{-154}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 1.15 \cdot 10^{-110}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 81.8%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    6. Step-by-step derivation
      1. *-commutative60.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow260.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    7. Simplified60.0%

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

    if 4.3999999999999999e-274 < n < 3.5000000000000001e-154 or 1.1500000000000001e-110 < n < 54

    1. Initial program 89.8%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    6. Step-by-step derivation
      1. mul-1-neg68.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
      2. unpow268.8%

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in68.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    7. Simplified68.8%

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

    if 3.5000000000000001e-154 < n < 1.1500000000000001e-110

    1. Initial program 80.0%

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

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

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

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

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

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

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

    if 54 < n

    1. Initial program 70.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 4.4 \cdot 10^{-274}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;n \leq 3.5 \cdot 10^{-154}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;n \leq 1.15 \cdot 10^{-110}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]

Alternative 5: 62.1% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{M \cdot \left(-M\right)}\\
\mathbf{if}\;n \leq 1.65 \cdot 10^{-280}:\\
\;\;\;\;e^{\left|m - n\right| - m \cdot \left(m \cdot 0.25\right)}\\

\mathbf{elif}\;n \leq 3.4 \cdot 10^{-154}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 2.35 \cdot 10^{-110}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 82.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. Taylor expanded in K around 0 97.2%

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

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

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

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

      \[\leadsto e^{\left|m - n\right| - \color{blue}{0.25 \cdot {m}^{2}}} \]
    7. Step-by-step derivation
      1. unpow252.5%

        \[\leadsto e^{\left|m - n\right| - 0.25 \cdot \color{blue}{\left(m \cdot m\right)}} \]
      2. associate-*r*52.5%

        \[\leadsto e^{\left|m - n\right| - \color{blue}{\left(0.25 \cdot m\right) \cdot m}} \]
    8. Simplified52.5%

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

    if 1.64999999999999995e-280 < n < 3.3999999999999998e-154 or 2.34999999999999996e-110 < n < 54

    1. Initial program 88.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. Taylor expanded in K around 0 97.0%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    6. Step-by-step derivation
      1. mul-1-neg68.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
      2. unpow268.5%

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-in68.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    7. Simplified68.5%

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

    if 3.3999999999999998e-154 < n < 2.34999999999999996e-110

    1. Initial program 80.0%

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

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

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

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

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

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

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

    if 54 < n

    1. Initial program 70.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 1.65 \cdot 10^{-280}:\\ \;\;\;\;e^{\left|m - n\right| - m \cdot \left(m \cdot 0.25\right)}\\ \mathbf{elif}\;n \leq 3.4 \cdot 10^{-154}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;n \leq 2.35 \cdot 10^{-110}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]

Alternative 6: 65.9% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 4.2:\\ \;\;\;\;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 (<= l 4.2) (exp (* m (* m -0.25))) (exp (- l))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (l <= 4.2) {
		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 (l <= 4.2d0) 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 (l <= 4.2) {
		tmp = Math.exp((m * (m * -0.25)));
	} else {
		tmp = Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if l <= 4.2:
		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 (l <= 4.2)
		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 (l <= 4.2)
		tmp = exp((m * (m * -0.25)));
	else
		tmp = exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[l, 4.2], N[Exp[N[(m * N[(m * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[(-l)], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 4.2:\\
\;\;\;\;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 l < 4.20000000000000018

    1. Initial program 77.9%

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

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

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

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

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

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

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

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

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

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

    if 4.20000000000000018 < l

    1. Initial program 85.5%

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{-\ell}} \]
    8. Simplified98.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 4.2:\\ \;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 7: 66.0% accurate, 4.0× speedup?

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

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

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


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

    1. Initial program 78.5%

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

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

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

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

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

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

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

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

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

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

    if -3.6e6 < m

    1. Initial program 80.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -3600000:\\ \;\;\;\;e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]

Alternative 8: 34.9% 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 80.2%

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{-\ell}} \]
  8. Simplified37.5%

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

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

Alternative 9: 7.2% 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 80.2%

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

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot m\right) - M\right)} \]
  6. Step-by-step derivation
    1. *-commutative7.3%

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(m \cdot K\right)} - M\right) \]
  7. Simplified7.3%

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

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

      \[\leadsto \color{blue}{\cos M} \]
  10. Simplified7.9%

    \[\leadsto \color{blue}{\cos M} \]
  11. Final simplification7.9%

    \[\leadsto \cos M \]

Reproduce

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