Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.7% → 96.7%
Time: 20.5s
Alternatives: 10
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

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

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

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

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

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

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

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

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

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

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

Alternative 2: 68.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -60000:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{elif}\;m \leq 5.5 \cdot 10^{-238}:\\ \;\;\;\;\cos M \cdot e^{\left|m - n\right| - \left(\ell + M \cdot M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -60000.0)
   (* (cos M) (exp (* m (* m -0.25))))
   (if (<= m 5.5e-238)
     (* (cos M) (exp (- (fabs (- m n)) (+ l (* 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 <= -60000.0) {
		tmp = cos(M) * exp((m * (m * -0.25)));
	} else if (m <= 5.5e-238) {
		tmp = cos(M) * exp((fabs((m - n)) - (l + (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 <= (-60000.0d0)) then
        tmp = cos(m_1) * exp((m * (m * (-0.25d0))))
    else if (m <= 5.5d-238) then
        tmp = cos(m_1) * exp((abs((m - n)) - (l + (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 <= -60000.0) {
		tmp = Math.cos(M) * Math.exp((m * (m * -0.25)));
	} else if (m <= 5.5e-238) {
		tmp = Math.cos(M) * Math.exp((Math.abs((m - n)) - (l + (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 <= -60000.0:
		tmp = math.cos(M) * math.exp((m * (m * -0.25)))
	elif m <= 5.5e-238:
		tmp = math.cos(M) * math.exp((math.fabs((m - n)) - (l + (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 <= -60000.0)
		tmp = Float64(cos(M) * exp(Float64(m * Float64(m * -0.25))));
	elseif (m <= 5.5e-238)
		tmp = Float64(cos(M) * exp(Float64(abs(Float64(m - n)) - Float64(l + Float64(M * M)))));
	else
		tmp = Float64(cos(M) * exp(Float64(n * Float64(n * -0.25))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -60000.0)
		tmp = cos(M) * exp((m * (m * -0.25)));
	elseif (m <= 5.5e-238)
		tmp = cos(M) * exp((abs((m - n)) - (l + (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, -60000.0], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(m * N[(m * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[m, 5.5e-238], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(l + N[(M * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(n * N[(n * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6e4 < m < 5.49999999999999995e-238

    1. Initial program 86.7%

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

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

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

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

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

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

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

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

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

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

    if 5.49999999999999995e-238 < m

    1. Initial program 66.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*l*56.7%

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

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

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

Alternative 3: 67.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\cos M}{e^{\ell}}\\ t_1 := {\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \mathbf{if}\;n \leq -1.26 \cdot 10^{-24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq -1.55 \cdot 10^{-213}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 9.2 \cdot 10^{-232}:\\ \;\;\;\;\frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{1 + m \cdot \left(m \cdot 0.25\right)}\\ \mathbf{elif}\;n \leq 510000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (/ (cos M) (exp l))) (t_1 (pow (exp n) (* n -0.25))))
   (if (<= n -1.26e-24)
     t_1
     (if (<= n -1.55e-213)
       t_0
       (if (<= n 9.2e-232)
         (/ (cos (- (* (/ (+ m n) 2.0) K) M)) (+ 1.0 (* m (* m 0.25))))
         (if (<= n 510000.0) t_0 t_1))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) / exp(l);
	double t_1 = pow(exp(n), (n * -0.25));
	double tmp;
	if (n <= -1.26e-24) {
		tmp = t_1;
	} else if (n <= -1.55e-213) {
		tmp = t_0;
	} else if (n <= 9.2e-232) {
		tmp = cos(((((m + n) / 2.0) * K) - M)) / (1.0 + (m * (m * 0.25)));
	} else if (n <= 510000.0) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = cos(m_1) / exp(l)
    t_1 = exp(n) ** (n * (-0.25d0))
    if (n <= (-1.26d-24)) then
        tmp = t_1
    else if (n <= (-1.55d-213)) then
        tmp = t_0
    else if (n <= 9.2d-232) then
        tmp = cos(((((m + n) / 2.0d0) * k) - m_1)) / (1.0d0 + (m * (m * 0.25d0)))
    else if (n <= 510000.0d0) then
        tmp = t_0
    else
        tmp = t_1
    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(l);
	double t_1 = Math.pow(Math.exp(n), (n * -0.25));
	double tmp;
	if (n <= -1.26e-24) {
		tmp = t_1;
	} else if (n <= -1.55e-213) {
		tmp = t_0;
	} else if (n <= 9.2e-232) {
		tmp = Math.cos(((((m + n) / 2.0) * K) - M)) / (1.0 + (m * (m * 0.25)));
	} else if (n <= 510000.0) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(M) / math.exp(l)
	t_1 = math.pow(math.exp(n), (n * -0.25))
	tmp = 0
	if n <= -1.26e-24:
		tmp = t_1
	elif n <= -1.55e-213:
		tmp = t_0
	elif n <= 9.2e-232:
		tmp = math.cos(((((m + n) / 2.0) * K) - M)) / (1.0 + (m * (m * 0.25)))
	elif n <= 510000.0:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) / exp(l))
	t_1 = exp(n) ^ Float64(n * -0.25)
	tmp = 0.0
	if (n <= -1.26e-24)
		tmp = t_1;
	elseif (n <= -1.55e-213)
		tmp = t_0;
	elseif (n <= 9.2e-232)
		tmp = Float64(cos(Float64(Float64(Float64(Float64(m + n) / 2.0) * K) - M)) / Float64(1.0 + Float64(m * Float64(m * 0.25))));
	elseif (n <= 510000.0)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = cos(M) / exp(l);
	t_1 = exp(n) ^ (n * -0.25);
	tmp = 0.0;
	if (n <= -1.26e-24)
		tmp = t_1;
	elseif (n <= -1.55e-213)
		tmp = t_0;
	elseif (n <= 9.2e-232)
		tmp = cos(((((m + n) / 2.0) * K) - M)) / (1.0 + (m * (m * 0.25)));
	elseif (n <= 510000.0)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Exp[n], $MachinePrecision], N[(n * -0.25), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, -1.26e-24], t$95$1, If[LessEqual[n, -1.55e-213], t$95$0, If[LessEqual[n, 9.2e-232], N[(N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] * K), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] / N[(1.0 + N[(m * N[(m * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 510000.0], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\cos M}{e^{\ell}}\\
t_1 := {\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\
\mathbf{if}\;n \leq -1.26 \cdot 10^{-24}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;n \leq -1.55 \cdot 10^{-213}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 9.2 \cdot 10^{-232}:\\
\;\;\;\;\frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{1 + m \cdot \left(m \cdot 0.25\right)}\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -1.25999999999999992e-24 or 5.1e5 < n

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*l*93.7%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
    10. Taylor expanded in M around 0 93.7%

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

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

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*r*93.7%

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

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

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

    if -1.25999999999999992e-24 < n < -1.5499999999999999e-213 or 9.2e-232 < n < 5.1e5

    1. Initial program 85.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. sub-neg85.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.5499999999999999e-213 < n < 9.2e-232

    1. Initial program 85.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. sub-neg85.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(K \cdot \frac{m + n}{2} - M\right)}{1 + \color{blue}{\left(m \cdot m\right)} \cdot 0.25} \]
      3. associate-*r*32.3%

        \[\leadsto \frac{\cos \left(K \cdot \frac{m + n}{2} - M\right)}{1 + \color{blue}{m \cdot \left(m \cdot 0.25\right)}} \]
    12. Simplified32.3%

      \[\leadsto \frac{\cos \left(K \cdot \frac{m + n}{2} - M\right)}{\color{blue}{1 + m \cdot \left(m \cdot 0.25\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification68.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -1.26 \cdot 10^{-24}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \mathbf{elif}\;n \leq -1.55 \cdot 10^{-213}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{elif}\;n \leq 9.2 \cdot 10^{-232}:\\ \;\;\;\;\frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{1 + m \cdot \left(m \cdot 0.25\right)}\\ \mathbf{elif}\;n \leq 510000:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 4: 65.0% accurate, 2.0× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1550 < m < 8.99999999999999962e-249

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.99999999999999962e-249 < m

    1. Initial program 67.7%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow256.2%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*l*56.2%

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

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

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

Alternative 5: 76.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := {\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\
\mathbf{if}\;n \leq -54:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 2.8 \cdot 10^{-25}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\

\mathbf{elif}\;n \leq 510000:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

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


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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*l*97.8%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
    10. Taylor expanded in M around 0 97.8%

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

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

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*r*97.8%

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

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

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

    if -54 < n < 2.79999999999999988e-25

    1. Initial program 84.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.79999999999999988e-25 < n < 5.1e5

    1. Initial program 75.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. sub-neg75.0%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -54:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \mathbf{elif}\;n \leq 2.8 \cdot 10^{-25}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;n \leq 510000:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 6: 65.0% accurate, 2.0× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1550 < m < 5.0000000000000002e-237

    1. Initial program 86.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.0000000000000002e-237 < m

    1. Initial program 66.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*l*56.7%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
    10. Taylor expanded in M around 0 56.7%

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

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

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*r*56.7%

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

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

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

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

Alternative 7: 39.6% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -8.5 \cdot 10^{+164}:\\
\;\;\;\;\frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{1 + m \cdot \left(m \cdot 0.25\right)}\\

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


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

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(K \cdot \frac{m + n}{2} - M\right)}{1 + \color{blue}{\left(m \cdot m\right)} \cdot 0.25} \]
      3. associate-*r*73.2%

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

      \[\leadsto \frac{\cos \left(K \cdot \frac{m + n}{2} - M\right)}{\color{blue}{1 + m \cdot \left(m \cdot 0.25\right)}} \]

    if -8.50000000000000027e164 < m

    1. Initial program 75.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. Step-by-step derivation
      1. sub-neg75.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 39.2% accurate, 3.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -8.5 \cdot 10^{+164}:\\ \;\;\;\;\frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{1 + 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 (<= m -8.5e+164)
   (/ (cos (- (* (/ (+ m n) 2.0) K) M)) (+ 1.0 (* m (* m 0.25))))
   (exp (- l))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -8.5e+164) {
		tmp = cos(((((m + n) / 2.0) * K) - M)) / (1.0 + (m * (m * 0.25)));
	} else {
		tmp = exp(-l);
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: tmp
    if (m <= (-8.5d+164)) then
        tmp = cos(((((m + n) / 2.0d0) * k) - m_1)) / (1.0d0 + (m * (m * 0.25d0)))
    else
        tmp = exp(-l)
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -8.5e+164) {
		tmp = Math.cos(((((m + n) / 2.0) * K) - M)) / (1.0 + (m * (m * 0.25)));
	} else {
		tmp = Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -8.5e+164:
		tmp = math.cos(((((m + n) / 2.0) * K) - M)) / (1.0 + (m * (m * 0.25)))
	else:
		tmp = math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -8.5e+164)
		tmp = Float64(cos(Float64(Float64(Float64(Float64(m + n) / 2.0) * K) - M)) / Float64(1.0 + Float64(m * Float64(m * 0.25))));
	else
		tmp = exp(Float64(-l));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -8.5e+164)
		tmp = cos(((((m + n) / 2.0) * K) - M)) / (1.0 + (m * (m * 0.25)));
	else
		tmp = exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -8.5e+164], N[(N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] * K), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] / N[(1.0 + N[(m * N[(m * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Exp[(-l)], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -8.5 \cdot 10^{+164}:\\
\;\;\;\;\frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{1 + m \cdot \left(m \cdot 0.25\right)}\\

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


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

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\cos \left(K \cdot \frac{m + n}{2} - M\right)}{1 + \color{blue}{\left(m \cdot m\right)} \cdot 0.25} \]
      3. associate-*r*73.2%

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

      \[\leadsto \frac{\cos \left(K \cdot \frac{m + n}{2} - M\right)}{\color{blue}{1 + m \cdot \left(m \cdot 0.25\right)}} \]

    if -8.50000000000000027e164 < m

    1. Initial program 75.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. Step-by-step derivation
      1. sub-neg75.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 35.1% 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.8%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Step-by-step derivation
    1. sub-neg74.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 6.8% accurate, 141.7× speedup?

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

\\
1 - \ell
\end{array}
Derivation
  1. Initial program 74.8%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Step-by-step derivation
    1. sub-neg74.8%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(\ell \cdot \cos M\right) + \cos M} \]
  9. Step-by-step derivation
    1. +-commutative6.5%

      \[\leadsto \color{blue}{\cos M + -1 \cdot \left(\ell \cdot \cos M\right)} \]
    2. mul-1-neg6.5%

      \[\leadsto \cos M + \color{blue}{\left(-\ell \cdot \cos M\right)} \]
    3. unsub-neg6.5%

      \[\leadsto \color{blue}{\cos M - \ell \cdot \cos M} \]
    4. *-commutative6.5%

      \[\leadsto \cos M - \color{blue}{\cos M \cdot \ell} \]
  10. Simplified6.5%

    \[\leadsto \color{blue}{\cos M - \cos M \cdot \ell} \]
  11. Taylor expanded in M around 0 6.5%

    \[\leadsto \color{blue}{1 - \ell} \]
  12. Final simplification6.5%

    \[\leadsto 1 - \ell \]

Reproduce

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