Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.0% → 96.4%
Time: 15.6s
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: 76.0% 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.4% 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 74.6%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Taylor expanded in K around 0 97.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-neg97.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. Simplified97.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 simplification97.1%

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

Alternative 2: 81.5% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 55:\\
\;\;\;\;\cos \left(\frac{n \cdot K}{2} - M\right) \cdot e^{\left(\left(m - n\right) - {\left(n \cdot 0.5 - M\right)}^{2}\right) - \ell}\\

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


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

    1. Initial program 77.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 m around 0 86.9%

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

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

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

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

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

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

        \[\leadsto \cos \left(\frac{K \cdot n}{2} - M\right) \cdot e^{\left(\color{blue}{{\left(m - n\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(m - n\right)}^{\left(\frac{1}{2}\right)}} - {\left(0.5 \cdot n - M\right)}^{2}\right) - \ell} \]
      6. sqr-pow77.2%

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

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

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

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

    if 55 < n

    1. Initial program 66.7%

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

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

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

        \[\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} \]
    7. Simplified96.9%

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

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

Alternative 3: 74.3% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 54:\\
\;\;\;\;\cos \left(\frac{n \cdot K}{2} - M\right) \cdot e^{\left(\left(m - n\right) - M \cdot M\right) - \ell}\\

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


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

    1. Initial program 77.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 m around 0 86.9%

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

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

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

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

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

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

        \[\leadsto \cos \left(\frac{K \cdot n}{2} - M\right) \cdot e^{\left(\color{blue}{{\left(m - n\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(m - n\right)}^{\left(\frac{1}{2}\right)}} - {\left(0.5 \cdot n - M\right)}^{2}\right) - \ell} \]
      6. sqr-pow77.2%

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

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

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

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

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

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

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

    if 54 < n

    1. Initial program 66.7%

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

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

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

        \[\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} \]
    7. Simplified96.9%

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

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

Alternative 4: 73.9% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 77.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 m around 0 86.9%

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

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

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

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

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

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

        \[\leadsto \cos \left(\frac{K \cdot n}{2} - M\right) \cdot e^{\left(\color{blue}{{\left(m - n\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(m - n\right)}^{\left(\frac{1}{2}\right)}} - {\left(0.5 \cdot n - M\right)}^{2}\right) - \ell} \]
      6. sqr-pow77.2%

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

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

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

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

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

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

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

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

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

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

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

    if 55 < n

    1. Initial program 66.7%

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

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

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

        \[\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} \]
    7. Simplified96.9%

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

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

Alternative 5: 74.7% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq 3.4 \cdot 10^{-189}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\

\mathbf{elif}\;m \leq 1.6:\\
\;\;\;\;e^{-\ell}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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

    1. Initial program 66.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 99.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-neg99.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. Simplified99.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 inf 97.1%

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

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

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

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

    if -39 < m < 3.4000000000000001e-189

    1. Initial program 81.9%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Taylor expanded in K around 0 96.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-neg96.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. Simplified96.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 60.4%

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

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

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

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

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

    if 3.4000000000000001e-189 < m < 1.6000000000000001

    1. Initial program 87.1%

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. associate-*r/61.1%

        \[\leadsto \color{blue}{\frac{\cos \left(-M\right) \cdot 1}{e^{\ell}}} \]
      3. *-rgt-identity61.1%

        \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
      4. cos-neg61.1%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Simplified61.1%

      \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    8. Taylor expanded in M around 0 61.1%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    9. Step-by-step derivation
      1. rec-exp61.1%

        \[\leadsto \color{blue}{e^{-\ell}} \]
    10. Simplified61.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -39:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq 3.4 \cdot 10^{-189}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;m \leq 1.6:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \end{array} \]

Alternative 6: 65.1% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq 1.02 \cdot 10^{-269}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\

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


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

    1. Initial program 77.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 100.0%

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

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

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

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

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

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

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

    if -39 < m < 1.02000000000000002e-269

    1. Initial program 83.6%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Taylor expanded in K around 0 98.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-neg98.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. Simplified98.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 inf 60.3%

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

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

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

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

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

    if 1.02000000000000002e-269 < m

    1. Initial program 69.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 95.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-neg95.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. Simplified95.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 n around inf 52.0%

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

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

        \[\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} \]
    7. Simplified52.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -39:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq 1.02 \cdot 10^{-269}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(n \cdot n\right) \cdot -0.25}\\ \end{array} \]

Alternative 7: 72.9% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7.5 \cdot 10^{-9}:\\
\;\;\;\;\cos M \cdot e^{\ell}\\

\mathbf{elif}\;\ell \leq 720:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -7.49999999999999933e-9

    1. Initial program 70.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 l around inf 20.5%

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. associate-*r/20.9%

        \[\leadsto \color{blue}{\frac{\cos \left(-M\right) \cdot 1}{e^{\ell}}} \]
      3. *-rgt-identity20.9%

        \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
      4. cos-neg20.9%

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

      \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u17.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\cos M}{e^{\ell}}\right)\right)} \]
      2. expm1-udef17.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\cos M}{e^{\ell}}\right)} - 1} \]
      3. div-inv17.2%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\cos M \cdot \frac{1}{e^{\ell}}}\right)} - 1 \]
      4. exp-neg17.2%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot \color{blue}{e^{-\ell}}\right)} - 1 \]
      5. add-sqr-sqrt17.2%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}}\right)} - 1 \]
      6. sqrt-unprod17.2%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}}\right)} - 1 \]
      7. sqr-neg17.2%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\sqrt{\color{blue}{\ell \cdot \ell}}}\right)} - 1 \]
      8. sqrt-unprod0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}\right)} - 1 \]
      9. add-sqr-sqrt72.6%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\color{blue}{\ell}}\right)} - 1 \]
    9. Applied egg-rr72.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos M \cdot e^{\ell}\right)} - 1} \]
    10. Step-by-step derivation
      1. expm1-def72.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos M \cdot e^{\ell}\right)\right)} \]
      2. expm1-log1p72.6%

        \[\leadsto \color{blue}{\cos M \cdot e^{\ell}} \]
      3. *-commutative72.6%

        \[\leadsto \color{blue}{e^{\ell} \cdot \cos M} \]
    11. Simplified72.6%

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

    if -7.49999999999999933e-9 < l < 720

    1. Initial program 76.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Taylor expanded in K around 0 97.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-neg97.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. Simplified97.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 inf 59.7%

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

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

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

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

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

    if 720 < l

    1. Initial program 75.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 l around inf 75.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-neg75.3%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    4. Simplified75.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 100.0%

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

        \[\leadsto \cos \left(-M\right) \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. associate-*r/100.0%

        \[\leadsto \color{blue}{\frac{\cos \left(-M\right) \cdot 1}{e^{\ell}}} \]
      3. *-rgt-identity100.0%

        \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
      4. cos-neg100.0%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    8. Taylor expanded in M around 0 100.0%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    9. Step-by-step derivation
      1. rec-exp100.0%

        \[\leadsto \color{blue}{e^{-\ell}} \]
    10. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.5 \cdot 10^{-9}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq 720:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 8: 57.2% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
\mathbf{if}\;\ell \leq -700:\\
\;\;\;\;\cos M \cdot e^{\ell}\\

\mathbf{elif}\;\ell \leq 2.5 \cdot 10^{-14}:\\
\;\;\;\;t_0 \cdot \left(\left(m \cdot m\right) \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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

    1. Initial program 70.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 20.8%

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. associate-*r/21.1%

        \[\leadsto \color{blue}{\frac{\cos \left(-M\right) \cdot 1}{e^{\ell}}} \]
      3. *-rgt-identity21.1%

        \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
      4. cos-neg21.1%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Simplified21.1%

      \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    8. Step-by-step derivation
      1. expm1-log1p-u17.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\cos M}{e^{\ell}}\right)\right)} \]
      2. expm1-udef17.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\cos M}{e^{\ell}}\right)} - 1} \]
      3. div-inv17.5%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\cos M \cdot \frac{1}{e^{\ell}}}\right)} - 1 \]
      4. exp-neg17.5%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot \color{blue}{e^{-\ell}}\right)} - 1 \]
      5. add-sqr-sqrt17.5%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\color{blue}{\sqrt{-\ell} \cdot \sqrt{-\ell}}}\right)} - 1 \]
      6. sqrt-unprod17.5%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\color{blue}{\sqrt{\left(-\ell\right) \cdot \left(-\ell\right)}}}\right)} - 1 \]
      7. sqr-neg17.5%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\sqrt{\color{blue}{\ell \cdot \ell}}}\right)} - 1 \]
      8. sqrt-unprod0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}\right)} - 1 \]
      9. add-sqr-sqrt73.8%

        \[\leadsto e^{\mathsf{log1p}\left(\cos M \cdot e^{\color{blue}{\ell}}\right)} - 1 \]
    9. Applied egg-rr73.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos M \cdot e^{\ell}\right)} - 1} \]
    10. Step-by-step derivation
      1. expm1-def73.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos M \cdot e^{\ell}\right)\right)} \]
      2. expm1-log1p73.8%

        \[\leadsto \color{blue}{\cos M \cdot e^{\ell}} \]
      3. *-commutative73.8%

        \[\leadsto \color{blue}{e^{\ell} \cdot \cos M} \]
    11. Simplified73.8%

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

    if -700 < l < 2.5000000000000001e-14

    1. Initial program 76.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 l around inf 13.7%

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

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

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

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

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

        \[\leadsto \left(1 + -0.125 \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot {m}^{2}\right)\right) \cdot e^{-\ell} \]
      2. unpow211.1%

        \[\leadsto \left(1 + -0.125 \cdot \left(\left(K \cdot K\right) \cdot \color{blue}{\left(m \cdot m\right)}\right)\right) \cdot e^{-\ell} \]
    8. Simplified11.1%

      \[\leadsto \color{blue}{\left(1 + -0.125 \cdot \left(\left(K \cdot K\right) \cdot \left(m \cdot m\right)\right)\right)} \cdot e^{-\ell} \]
    9. Taylor expanded in K around inf 30.8%

      \[\leadsto \color{blue}{\left(-0.125 \cdot \left({K}^{2} \cdot {m}^{2}\right)\right)} \cdot e^{-\ell} \]
    10. Step-by-step derivation
      1. associate-*r*30.8%

        \[\leadsto \color{blue}{\left(\left(-0.125 \cdot {K}^{2}\right) \cdot {m}^{2}\right)} \cdot e^{-\ell} \]
      2. unpow230.8%

        \[\leadsto \left(\left(-0.125 \cdot \color{blue}{\left(K \cdot K\right)}\right) \cdot {m}^{2}\right) \cdot e^{-\ell} \]
      3. unpow230.8%

        \[\leadsto \left(\left(-0.125 \cdot \left(K \cdot K\right)\right) \cdot \color{blue}{\left(m \cdot m\right)}\right) \cdot e^{-\ell} \]
      4. associate-*r*30.8%

        \[\leadsto \left(\color{blue}{\left(\left(-0.125 \cdot K\right) \cdot K\right)} \cdot \left(m \cdot m\right)\right) \cdot e^{-\ell} \]
    11. Simplified30.8%

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

    if 2.5000000000000001e-14 < l

    1. Initial program 75.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 l around inf 72.8%

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. associate-*r/96.2%

        \[\leadsto \color{blue}{\frac{\cos \left(-M\right) \cdot 1}{e^{\ell}}} \]
      3. *-rgt-identity96.2%

        \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
      4. cos-neg96.2%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Simplified96.2%

      \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    8. Taylor expanded in M around 0 96.2%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    9. Step-by-step derivation
      1. rec-exp96.2%

        \[\leadsto \color{blue}{e^{-\ell}} \]
    10. Simplified96.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -700:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{-14}:\\ \;\;\;\;e^{-\ell} \cdot \left(\left(m \cdot m\right) \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 9: 43.4% accurate, 3.7× speedup?

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

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
\mathbf{if}\;\ell \leq -700 \lor \neg \left(\ell \leq 2 \cdot 10^{-14}\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(\left(m \cdot m\right) \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -700 or 2e-14 < l

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. associate-*r/63.3%

        \[\leadsto \color{blue}{\frac{\cos \left(-M\right) \cdot 1}{e^{\ell}}} \]
      3. *-rgt-identity63.3%

        \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
      4. cos-neg63.3%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Simplified63.3%

      \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    8. Taylor expanded in M around 0 62.6%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    9. Step-by-step derivation
      1. rec-exp62.6%

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

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

    if -700 < l < 2e-14

    1. Initial program 76.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 l around inf 13.7%

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

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

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

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

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

        \[\leadsto \left(1 + -0.125 \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot {m}^{2}\right)\right) \cdot e^{-\ell} \]
      2. unpow211.1%

        \[\leadsto \left(1 + -0.125 \cdot \left(\left(K \cdot K\right) \cdot \color{blue}{\left(m \cdot m\right)}\right)\right) \cdot e^{-\ell} \]
    8. Simplified11.1%

      \[\leadsto \color{blue}{\left(1 + -0.125 \cdot \left(\left(K \cdot K\right) \cdot \left(m \cdot m\right)\right)\right)} \cdot e^{-\ell} \]
    9. Taylor expanded in K around inf 30.8%

      \[\leadsto \color{blue}{\left(-0.125 \cdot \left({K}^{2} \cdot {m}^{2}\right)\right)} \cdot e^{-\ell} \]
    10. Step-by-step derivation
      1. associate-*r*30.8%

        \[\leadsto \color{blue}{\left(\left(-0.125 \cdot {K}^{2}\right) \cdot {m}^{2}\right)} \cdot e^{-\ell} \]
      2. unpow230.8%

        \[\leadsto \left(\left(-0.125 \cdot \color{blue}{\left(K \cdot K\right)}\right) \cdot {m}^{2}\right) \cdot e^{-\ell} \]
      3. unpow230.8%

        \[\leadsto \left(\left(-0.125 \cdot \left(K \cdot K\right)\right) \cdot \color{blue}{\left(m \cdot m\right)}\right) \cdot e^{-\ell} \]
      4. associate-*r*30.8%

        \[\leadsto \left(\color{blue}{\left(\left(-0.125 \cdot K\right) \cdot K\right)} \cdot \left(m \cdot m\right)\right) \cdot e^{-\ell} \]
    11. Simplified30.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -700 \lor \neg \left(\ell \leq 2 \cdot 10^{-14}\right):\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell} \cdot \left(\left(m \cdot m\right) \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \end{array} \]

Alternative 10: 35.5% 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 74.6%

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

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

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

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

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

      \[\leadsto \cos \left(-M\right) \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
    2. associate-*r/40.4%

      \[\leadsto \color{blue}{\frac{\cos \left(-M\right) \cdot 1}{e^{\ell}}} \]
    3. *-rgt-identity40.4%

      \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{\ell}} \]
    4. cos-neg40.4%

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
  7. Simplified40.4%

    \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
  8. Taylor expanded in M around 0 40.0%

    \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
  9. Step-by-step derivation
    1. rec-exp40.0%

      \[\leadsto \color{blue}{e^{-\ell}} \]
  10. Simplified40.0%

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

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

Alternative 11: 7.0% 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 74.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \]
  8. Simplified8.5%

    \[\leadsto \color{blue}{\cos M} \]
  9. Final simplification8.5%

    \[\leadsto \cos M \]

Reproduce

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