Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.9% → 97.0%
Time: 21.9s
Alternatives: 15
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 97.0% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.4% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -3 \cdot 10^{+30}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{\left(n \cdot 0.5 - M\right) \cdot \left(\left(M - n \cdot 0.5\right) - m\right) + \left(\left|n - m\right| - \ell\right)}\\


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

    1. Initial program 61.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*61.1%

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

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

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

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

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

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

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

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

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

    if -2.99999999999999978e30 < m

    1. Initial program 79.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*80.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. +-commutative80.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out82.7%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{n \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot n - M\right) + m\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      5. *-commutative82.7%

        \[\leadsto \cos M \cdot e^{\left(-\left(n \cdot 0.5 - M\right) \cdot \left(\left(\color{blue}{n \cdot 0.5} - M\right) + m\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
    10. Simplified82.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -3 \cdot 10^{+30}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {m}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(n \cdot 0.5 - M\right) \cdot \left(\left(M - n \cdot 0.5\right) - m\right) + \left(\left|n - m\right| - \ell\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 78.4% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -27 \lor \neg \left(M \leq 30\right):\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -27 or 30 < M

    1. Initial program 82.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*83.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. +-commutative83.0%

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

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

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

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

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

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

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

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

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

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

    if -27 < M < 30

    1. Initial program 68.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*69.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. +-commutative69.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out68.7%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{n \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot n - M\right) + m\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      5. *-commutative68.7%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+32.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| - \ell\right) - -1 \cdot \left(M \cdot \left(m - M\right)\right)}} \]
      2. sub-neg32.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-132.9%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-132.9%

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(m - M\right)} \]
      6. cancel-sign-sub32.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-132.9%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|\color{blue}{{\left(n - m\right)}^{1}}\right| - \ell\right) + M \cdot \left(m - M\right)} \]
      10. sqr-pow18.8%

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(n - m\right)}^{\left(\frac{1}{2}\right)}} - \ell\right) + M \cdot \left(m - M\right)} \]
      12. sqr-pow68.7%

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{1}} - \ell\right) + M \cdot \left(m - M\right)} \]
      13. unpow168.7%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left(n - m\right) - \ell\right) + M \cdot \left(m - M\right)}} \]
    14. Step-by-step derivation
      1. associate-+l-68.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n - m\right) - \left(\ell - M \cdot \left(m - M\right)\right)}} \]
      2. add-sqr-sqrt18.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{n - m} \cdot \sqrt{n - m}} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      3. fabs-sqr18.8%

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left|m - n\right|} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      6. add-sqr-sqrt14.1%

        \[\leadsto \cos M \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      7. fabs-sqr14.1%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      8. add-sqr-sqrt56.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m - n\right)} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      9. sub-neg56.5%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \color{blue}{\left(m + \left(-M\right)\right)}\right)} \]
      10. add-sqr-sqrt26.0%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{-M} \cdot \sqrt{-M}}\right)\right)} \]
      11. sqrt-unprod56.5%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{\left(-M\right) \cdot \left(-M\right)}}\right)\right)} \]
      12. sqr-neg56.5%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \sqrt{\color{blue}{M \cdot M}}\right)\right)} \]
      13. sqrt-unprod30.5%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{M} \cdot \sqrt{M}}\right)\right)} \]
      14. add-sqr-sqrt56.5%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{M}\right)\right)} \]
    15. Applied egg-rr56.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -27 \lor \neg \left(M \leq 30\right):\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) + \left(M \cdot \left(M + m\right) - \ell\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 63.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ t_1 := \cos M \cdot e^{\ell}\\ \mathbf{if}\;\ell \leq -1.36 \cdot 10^{+202}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -2.1 \cdot 10^{+177}:\\ \;\;\;\;\left({M}^{2} \cdot -0.5 + 1\right) \cdot t\_0\\ \mathbf{elif}\;\ell \leq -2.2:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq 3.6:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- l))) (t_1 (* (cos M) (exp l))))
   (if (<= l -1.36e+202)
     t_1
     (if (<= l -2.1e+177)
       (* (+ (* (pow M 2.0) -0.5) 1.0) t_0)
       (if (<= l -2.2)
         t_1
         (if (<= l 3.6) (* (cos M) (exp (* m (- M (* n 0.5))))) t_0))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(-l);
	double t_1 = cos(M) * exp(l);
	double tmp;
	if (l <= -1.36e+202) {
		tmp = t_1;
	} else if (l <= -2.1e+177) {
		tmp = ((pow(M, 2.0) * -0.5) + 1.0) * t_0;
	} else if (l <= -2.2) {
		tmp = t_1;
	} else if (l <= 3.6) {
		tmp = cos(M) * exp((m * (M - (n * 0.5))));
	} 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) :: t_1
    real(8) :: tmp
    t_0 = exp(-l)
    t_1 = cos(m_1) * exp(l)
    if (l <= (-1.36d+202)) then
        tmp = t_1
    else if (l <= (-2.1d+177)) then
        tmp = (((m_1 ** 2.0d0) * (-0.5d0)) + 1.0d0) * t_0
    else if (l <= (-2.2d0)) then
        tmp = t_1
    else if (l <= 3.6d0) then
        tmp = cos(m_1) * exp((m * (m_1 - (n * 0.5d0))))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(-l);
	double t_1 = Math.cos(M) * Math.exp(l);
	double tmp;
	if (l <= -1.36e+202) {
		tmp = t_1;
	} else if (l <= -2.1e+177) {
		tmp = ((Math.pow(M, 2.0) * -0.5) + 1.0) * t_0;
	} else if (l <= -2.2) {
		tmp = t_1;
	} else if (l <= 3.6) {
		tmp = Math.cos(M) * Math.exp((m * (M - (n * 0.5))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp(-l)
	t_1 = math.cos(M) * math.exp(l)
	tmp = 0
	if l <= -1.36e+202:
		tmp = t_1
	elif l <= -2.1e+177:
		tmp = ((math.pow(M, 2.0) * -0.5) + 1.0) * t_0
	elif l <= -2.2:
		tmp = t_1
	elif l <= 3.6:
		tmp = math.cos(M) * math.exp((m * (M - (n * 0.5))))
	else:
		tmp = t_0
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(-l))
	t_1 = Float64(cos(M) * exp(l))
	tmp = 0.0
	if (l <= -1.36e+202)
		tmp = t_1;
	elseif (l <= -2.1e+177)
		tmp = Float64(Float64(Float64((M ^ 2.0) * -0.5) + 1.0) * t_0);
	elseif (l <= -2.2)
		tmp = t_1;
	elseif (l <= 3.6)
		tmp = Float64(cos(M) * exp(Float64(m * Float64(M - Float64(n * 0.5)))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(-l);
	t_1 = cos(M) * exp(l);
	tmp = 0.0;
	if (l <= -1.36e+202)
		tmp = t_1;
	elseif (l <= -2.1e+177)
		tmp = (((M ^ 2.0) * -0.5) + 1.0) * t_0;
	elseif (l <= -2.2)
		tmp = t_1;
	elseif (l <= 3.6)
		tmp = cos(M) * exp((m * (M - (n * 0.5))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[M], $MachinePrecision] * N[Exp[l], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.36e+202], t$95$1, If[LessEqual[l, -2.1e+177], N[(N[(N[(N[Power[M, 2.0], $MachinePrecision] * -0.5), $MachinePrecision] + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[l, -2.2], t$95$1, If[LessEqual[l, 3.6], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(m * N[(M - N[(n * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := \cos M \cdot e^{\ell}\\
\mathbf{if}\;\ell \leq -1.36 \cdot 10^{+202}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -2.1 \cdot 10^{+177}:\\
\;\;\;\;\left({M}^{2} \cdot -0.5 + 1\right) \cdot t\_0\\

\mathbf{elif}\;\ell \leq -2.2:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq 3.6:\\
\;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.36e202 or -2.10000000000000013e177 < l < -2.2000000000000002

    1. Initial program 83.1%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*84.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. +-commutative84.6%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    10. Simplified21.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.36e202 < l < -2.10000000000000013e177

    1. Initial program 50.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    9. Step-by-step derivation
      1. mul-1-neg66.7%

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

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

      \[\leadsto \color{blue}{e^{-\ell} + -0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    12. Step-by-step derivation
      1. associate-*r*0.0%

        \[\leadsto e^{-\ell} + \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. distribute-rgt1-in83.3%

        \[\leadsto \color{blue}{\left(-0.5 \cdot {M}^{2} + 1\right) \cdot e^{-\ell}} \]
    13. Simplified83.3%

      \[\leadsto \color{blue}{\left(-0.5 \cdot {M}^{2} + 1\right) \cdot e^{-\ell}} \]

    if -2.2000000000000002 < l < 3.60000000000000009

    1. Initial program 71.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out78.8%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{m \cdot \left(M - 0.5 \cdot n\right)}} \]
    12. Step-by-step derivation
      1. *-commutative43.8%

        \[\leadsto \cos M \cdot e^{m \cdot \left(M - \color{blue}{n \cdot 0.5}\right)} \]
    13. Simplified43.8%

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

    if 3.60000000000000009 < l

    1. Initial program 79.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*79.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    10. Simplified97.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.36 \cdot 10^{+202}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq -2.1 \cdot 10^{+177}:\\ \;\;\;\;\left({M}^{2} \cdot -0.5 + 1\right) \cdot e^{-\ell}\\ \mathbf{elif}\;\ell \leq -2.2:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq 3.6:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 69.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := M \cdot \left(M + m\right)\\
\mathbf{if}\;M \leq -9 \cdot 10^{+108}:\\
\;\;\;\;\cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - t\_0}\\

\mathbf{elif}\;M \leq -0.26:\\
\;\;\;\;\cos \left(\frac{n \cdot K}{2} - M\right) \cdot e^{m - \left(n + \ell\right)}\\

\mathbf{elif}\;M \leq 0.0095:\\
\;\;\;\;\cos M \cdot e^{\left(m - n\right) + \left(t\_0 - \ell\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \left(m + \ell\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if M < -9e108

    1. Initial program 78.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*78.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. +-commutative78.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out97.7%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{n \cdot 0.5} - M\right) \cdot \left(\left(0.5 \cdot n - M\right) + m\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      5. *-commutative97.7%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+95.3%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-195.3%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-195.3%

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(m - M\right)} \]
      6. cancel-sign-sub95.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-195.3%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|\color{blue}{{\left(n - m\right)}^{1}}\right| - \ell\right) + M \cdot \left(m - M\right)} \]
      10. sqr-pow54.8%

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

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{1}} - \ell\right) + M \cdot \left(m - M\right)} \]
      13. unpow195.3%

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{\left(n - m\right)} - \ell\right) + M \cdot \left(m - M\right)} \]
    13. Simplified95.3%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left(n - m\right) - \ell\right) + M \cdot \left(m - M\right)}} \]
    14. Step-by-step derivation
      1. add-sqr-sqrt52.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{\left(n - m\right) - \ell} \cdot \sqrt{\left(n - m\right) - \ell}} + M \cdot \left(m - M\right)} \]
      2. fma-def52.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, M \cdot \left(m - M\right)\right)}} \]
      3. add-sqr-sqrt0.0%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{\left(\sqrt{M} \cdot \sqrt{M}\right)} \cdot \left(m - M\right)\right)} \]
      4. sqrt-unprod5.6%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{\sqrt{M \cdot M}} \cdot \left(m - M\right)\right)} \]
      5. sqr-neg5.6%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \sqrt{\color{blue}{\left(-M\right) \cdot \left(-M\right)}} \cdot \left(m - M\right)\right)} \]
      6. sqrt-unprod5.6%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{\left(\sqrt{-M} \cdot \sqrt{-M}\right)} \cdot \left(m - M\right)\right)} \]
      7. add-sqr-sqrt5.6%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{\left(-M\right)} \cdot \left(m - M\right)\right)} \]
      8. distribute-lft-neg-out5.6%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{-M \cdot \left(m - M\right)}\right)} \]
      9. fma-neg5.6%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{\left(n - m\right) - \ell} \cdot \sqrt{\left(n - m\right) - \ell} - M \cdot \left(m - M\right)}} \]
      10. add-sqr-sqrt6.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left(n - m\right) - \ell\right)} - M \cdot \left(m - M\right)} \]
      11. associate--l-6.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n - \left(m + \ell\right)\right)} - M \cdot \left(m - M\right)} \]
      12. sub-neg6.3%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \color{blue}{\left(m + \left(-M\right)\right)}} \]
      13. add-sqr-sqrt6.3%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \color{blue}{\sqrt{-M} \cdot \sqrt{-M}}\right)} \]
      14. sqrt-unprod6.3%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \color{blue}{\sqrt{\left(-M\right) \cdot \left(-M\right)}}\right)} \]
      15. sqr-neg6.3%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \sqrt{\color{blue}{M \cdot M}}\right)} \]
      16. sqrt-unprod0.0%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \color{blue}{\sqrt{M} \cdot \sqrt{M}}\right)} \]
      17. add-sqr-sqrt90.6%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \color{blue}{M}\right)} \]
    15. Applied egg-rr90.6%

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

    if -9e108 < M < -0.26000000000000001

    1. Initial program 76.7%

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out86.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(\frac{K \cdot n}{2} - M\right) \cdot e^{\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell} \]
      3. rem-square-sqrt34.2%

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

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

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

    if -0.26000000000000001 < M < 0.00949999999999999976

    1. Initial program 68.5%

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

        \[\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. +-commutative69.3%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out68.5%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+32.4%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-132.4%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-132.4%

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(m - M\right)} \]
      6. cancel-sign-sub32.4%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-132.4%

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{1}} - \ell\right) + M \cdot \left(m - M\right)} \]
      13. unpow168.5%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left(n - m\right) - \ell\right) + M \cdot \left(m - M\right)}} \]
    14. Step-by-step derivation
      1. associate-+l-68.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n - m\right) - \left(\ell - M \cdot \left(m - M\right)\right)}} \]
      2. add-sqr-sqrt18.2%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{n - m} \cdot \sqrt{n - m}} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      3. fabs-sqr18.2%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left|\sqrt{n - m} \cdot \sqrt{n - m}\right|} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      4. add-sqr-sqrt32.4%

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

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

        \[\leadsto \cos M \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      7. fabs-sqr14.2%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      8. add-sqr-sqrt56.2%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m - n\right)} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      9. sub-neg56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \color{blue}{\left(m + \left(-M\right)\right)}\right)} \]
      10. add-sqr-sqrt26.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{-M} \cdot \sqrt{-M}}\right)\right)} \]
      11. sqrt-unprod56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{\left(-M\right) \cdot \left(-M\right)}}\right)\right)} \]
      12. sqr-neg56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \sqrt{\color{blue}{M \cdot M}}\right)\right)} \]
      13. sqrt-unprod30.0%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{M} \cdot \sqrt{M}}\right)\right)} \]
      14. add-sqr-sqrt56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{M}\right)\right)} \]
    15. Applied egg-rr56.2%

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

    if 0.00949999999999999976 < M

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out86.2%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+78.5%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-178.5%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-178.5%

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(m - M\right)} \]
      6. cancel-sign-sub78.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-178.5%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|\color{blue}{{\left(n - m\right)}^{1}}\right| - \ell\right) + M \cdot \left(m - M\right)} \]
      10. sqr-pow43.8%

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

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{1}} - \ell\right) + M \cdot \left(m - M\right)} \]
      13. unpow181.5%

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

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

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

        \[\leadsto \cos M \cdot e^{M \cdot \left(m - M\right) - \color{blue}{\left(m + \ell\right)}} \]
    16. Simplified86.2%

      \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(m - M\right) - \left(m + \ell\right)}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification66.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -9 \cdot 10^{+108}:\\ \;\;\;\;\cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(M + m\right)}\\ \mathbf{elif}\;M \leq -0.26:\\ \;\;\;\;\cos \left(\frac{n \cdot K}{2} - M\right) \cdot e^{m - \left(n + \ell\right)}\\ \mathbf{elif}\;M \leq 0.0095:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) + \left(M \cdot \left(M + m\right) - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \left(m + \ell\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 71.5% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -2.05 \cdot 10^{+65} \lor \neg \left(M \leq 0.0095\right):\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \left(m + \ell\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -2.0500000000000001e65 or 0.00949999999999999976 < M

    1. Initial program 84.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*84.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out90.8%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+84.2%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-184.2%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-184.2%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-184.2%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|\color{blue}{{\left(n - m\right)}^{1}}\right| - \ell\right) + M \cdot \left(m - M\right)} \]
      10. sqr-pow46.7%

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(n - m\right)}^{\left(\frac{1}{2}\right)}} - \ell\right) + M \cdot \left(m - M\right)} \]
      12. sqr-pow86.7%

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{1}} - \ell\right) + M \cdot \left(m - M\right)} \]
      13. unpow186.7%

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{\left(n - m\right)} - \ell\right) + M \cdot \left(m - M\right)} \]
    13. Simplified86.7%

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

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

        \[\leadsto \cos M \cdot e^{M \cdot \left(m - M\right) - \color{blue}{\left(m + \ell\right)}} \]
    16. Simplified90.0%

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

    if -2.0500000000000001e65 < M < 0.00949999999999999976

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out70.4%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+32.6%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-132.6%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-132.6%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-132.6%

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left(n - m\right) - \ell\right) + M \cdot \left(m - M\right)}} \]
    14. Step-by-step derivation
      1. associate-+l-67.6%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n - m\right) - \left(\ell - M \cdot \left(m - M\right)\right)}} \]
      2. add-sqr-sqrt15.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{n - m} \cdot \sqrt{n - m}} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      3. fabs-sqr15.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left|\sqrt{n - m} \cdot \sqrt{n - m}\right|} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      4. add-sqr-sqrt32.6%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left|m - n\right|} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      6. add-sqr-sqrt16.8%

        \[\leadsto \cos M \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      7. fabs-sqr16.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      8. add-sqr-sqrt56.2%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m - n\right)} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      9. sub-neg56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \color{blue}{\left(m + \left(-M\right)\right)}\right)} \]
      10. add-sqr-sqrt30.1%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{-M} \cdot \sqrt{-M}}\right)\right)} \]
      11. sqrt-unprod56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{\left(-M\right) \cdot \left(-M\right)}}\right)\right)} \]
      12. sqr-neg56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \sqrt{\color{blue}{M \cdot M}}\right)\right)} \]
      13. sqrt-unprod26.0%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{M} \cdot \sqrt{M}}\right)\right)} \]
      14. add-sqr-sqrt55.4%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{M}\right)\right)} \]
    15. Applied egg-rr55.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -2.05 \cdot 10^{+65} \lor \neg \left(M \leq 0.0095\right):\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \left(m + \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) + \left(M \cdot \left(M + m\right) - \ell\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 71.2% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := M \cdot \left(M + m\right)\\
\mathbf{if}\;M \leq -1.15 \cdot 10^{+63}:\\
\;\;\;\;\cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - t\_0}\\

\mathbf{elif}\;M \leq 0.0095:\\
\;\;\;\;\cos M \cdot e^{\left(m - n\right) + \left(t\_0 - \ell\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \left(m + \ell\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -1.14999999999999997e63

    1. Initial program 81.5%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*81.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. +-commutative81.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out96.4%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+90.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| - \ell\right) - -1 \cdot \left(M \cdot \left(m - M\right)\right)}} \]
      2. sub-neg90.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-190.9%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-190.9%

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(m - M\right)} \]
      6. cancel-sign-sub90.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-190.9%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|\color{blue}{{\left(n - m\right)}^{1}}\right| - \ell\right) + M \cdot \left(m - M\right)} \]
      10. sqr-pow50.1%

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(n - m\right)}^{\left(\frac{1}{2}\right)}} - \ell\right) + M \cdot \left(m - M\right)} \]
      12. sqr-pow92.7%

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{1}} - \ell\right) + M \cdot \left(m - M\right)} \]
      13. unpow192.7%

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{\left(n - m\right)} - \ell\right) + M \cdot \left(m - M\right)} \]
    13. Simplified92.7%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left(n - m\right) - \ell\right) + M \cdot \left(m - M\right)}} \]
    14. Step-by-step derivation
      1. add-sqr-sqrt48.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{\left(n - m\right) - \ell} \cdot \sqrt{\left(n - m\right) - \ell}} + M \cdot \left(m - M\right)} \]
      2. fma-def48.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, M \cdot \left(m - M\right)\right)}} \]
      3. add-sqr-sqrt0.0%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{\left(\sqrt{M} \cdot \sqrt{M}\right)} \cdot \left(m - M\right)\right)} \]
      4. sqrt-unprod6.3%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{\sqrt{M \cdot M}} \cdot \left(m - M\right)\right)} \]
      5. sqr-neg6.3%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \sqrt{\color{blue}{\left(-M\right) \cdot \left(-M\right)}} \cdot \left(m - M\right)\right)} \]
      6. sqrt-unprod6.3%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{\left(\sqrt{-M} \cdot \sqrt{-M}\right)} \cdot \left(m - M\right)\right)} \]
      7. add-sqr-sqrt6.3%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{\left(-M\right)} \cdot \left(m - M\right)\right)} \]
      8. distribute-lft-neg-out6.3%

        \[\leadsto \cos M \cdot e^{\mathsf{fma}\left(\sqrt{\left(n - m\right) - \ell}, \sqrt{\left(n - m\right) - \ell}, \color{blue}{-M \cdot \left(m - M\right)}\right)} \]
      9. fma-neg6.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{\left(n - m\right) - \ell} \cdot \sqrt{\left(n - m\right) - \ell} - M \cdot \left(m - M\right)}} \]
      10. add-sqr-sqrt8.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left(n - m\right) - \ell\right)} - M \cdot \left(m - M\right)} \]
      11. associate--l-8.9%

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

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \color{blue}{\left(m + \left(-M\right)\right)}} \]
      13. add-sqr-sqrt8.9%

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

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \color{blue}{\sqrt{\left(-M\right) \cdot \left(-M\right)}}\right)} \]
      15. sqr-neg8.9%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \sqrt{\color{blue}{M \cdot M}}\right)} \]
      16. sqrt-unprod0.0%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \color{blue}{\sqrt{M} \cdot \sqrt{M}}\right)} \]
      17. add-sqr-sqrt83.6%

        \[\leadsto \cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(m + \color{blue}{M}\right)} \]
    15. Applied egg-rr83.6%

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

    if -1.14999999999999997e63 < M < 0.00949999999999999976

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out70.4%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+32.6%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-132.6%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-132.6%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-132.6%

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left(n - m\right) - \ell\right) + M \cdot \left(m - M\right)}} \]
    14. Step-by-step derivation
      1. associate-+l-67.6%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n - m\right) - \left(\ell - M \cdot \left(m - M\right)\right)}} \]
      2. add-sqr-sqrt15.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{n - m} \cdot \sqrt{n - m}} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      3. fabs-sqr15.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left|\sqrt{n - m} \cdot \sqrt{n - m}\right|} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      4. add-sqr-sqrt32.6%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left|m - n\right|} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      6. add-sqr-sqrt16.8%

        \[\leadsto \cos M \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      7. fabs-sqr16.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      8. add-sqr-sqrt56.2%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m - n\right)} - \left(\ell - M \cdot \left(m - M\right)\right)} \]
      9. sub-neg56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \color{blue}{\left(m + \left(-M\right)\right)}\right)} \]
      10. add-sqr-sqrt30.1%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{-M} \cdot \sqrt{-M}}\right)\right)} \]
      11. sqrt-unprod56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{\left(-M\right) \cdot \left(-M\right)}}\right)\right)} \]
      12. sqr-neg56.2%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \sqrt{\color{blue}{M \cdot M}}\right)\right)} \]
      13. sqrt-unprod26.0%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{\sqrt{M} \cdot \sqrt{M}}\right)\right)} \]
      14. add-sqr-sqrt55.4%

        \[\leadsto \cos M \cdot e^{\left(m - n\right) - \left(\ell - M \cdot \left(m + \color{blue}{M}\right)\right)} \]
    15. Applied egg-rr55.4%

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

    if 0.00949999999999999976 < M

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out86.2%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+78.5%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-178.5%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-178.5%

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(m - M\right)} \]
      6. cancel-sign-sub78.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-178.5%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|\color{blue}{{\left(n - m\right)}^{1}}\right| - \ell\right) + M \cdot \left(m - M\right)} \]
      10. sqr-pow43.8%

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

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(n - m\right)}^{1}} - \ell\right) + M \cdot \left(m - M\right)} \]
      13. unpow181.5%

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

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

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

        \[\leadsto \cos M \cdot e^{M \cdot \left(m - M\right) - \color{blue}{\left(m + \ell\right)}} \]
    16. Simplified86.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -1.15 \cdot 10^{+63}:\\ \;\;\;\;\cos M \cdot e^{\left(n - \left(m + \ell\right)\right) - M \cdot \left(M + m\right)}\\ \mathbf{elif}\;M \leq 0.0095:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) + \left(M \cdot \left(M + m\right) - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \left(m + \ell\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 64.5% accurate, 1.9× speedup?

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

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

\mathbf{elif}\;\ell \leq 3.6:\\
\;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\

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


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

    1. Initial program 80.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    10. Simplified25.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    11. Step-by-step derivation
      1. expm1-log1p-u24.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M \cdot e^{\ell}} \]
    14. Simplified69.5%

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

    if -2.2000000000000002 < l < 3.60000000000000009

    1. Initial program 71.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out78.8%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{m \cdot \left(M - 0.5 \cdot n\right)}} \]
    12. Step-by-step derivation
      1. *-commutative43.8%

        \[\leadsto \cos M \cdot e^{m \cdot \left(M - \color{blue}{n \cdot 0.5}\right)} \]
    13. Simplified43.8%

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

    if 3.60000000000000009 < l

    1. Initial program 79.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*79.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    10. Simplified97.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq 3.6:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 64.3% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;\ell \leq 3.6:\\
\;\;\;\;\cos M \cdot e^{m \cdot \left(M + -1\right)}\\

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


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

    1. Initial program 80.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    10. Simplified25.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    11. Step-by-step derivation
      1. expm1-log1p-u24.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M \cdot e^{\ell}} \]
    14. Simplified69.5%

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

    if -2.2000000000000002 < l < 3.60000000000000009

    1. Initial program 71.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out78.8%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+48.8%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-148.8%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-148.8%

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(m - M\right)} \]
      6. cancel-sign-sub48.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-148.8%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|\color{blue}{{\left(n - m\right)}^{1}}\right| - \ell\right) + M \cdot \left(m - M\right)} \]
      10. sqr-pow23.5%

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

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

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

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

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

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

    if 3.60000000000000009 < l

    1. Initial program 79.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*79.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    10. Simplified97.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq 3.6:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(M + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 72.5% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -7 \cdot 10^{+138}:\\
\;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \left(m + \ell\right)}\\


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

    1. Initial program 60.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*60.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. +-commutative60.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out60.6%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{m \cdot \left(M - 0.5 \cdot n\right)}} \]
    12. Step-by-step derivation
      1. *-commutative47.5%

        \[\leadsto \cos M \cdot e^{m \cdot \left(M - \color{blue}{n \cdot 0.5}\right)} \]
    13. Simplified47.5%

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

    if -6.9999999999999996e138 < m

    1. Initial program 78.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)} + m \cdot \left(0.5 \cdot n - M\right)\right)\right) - \left(\ell - \left|n - m\right|\right)} \]
      3. distribute-rgt-out82.4%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|n - m\right| - \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    12. Step-by-step derivation
      1. associate--r+58.4%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + \left(-\ell\right)\right)} - -1 \cdot \left(M \cdot \left(m - M\right)\right)} \]
      3. neg-mul-158.4%

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

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(m - M\right)}} \]
      5. neg-mul-158.4%

        \[\leadsto \cos M \cdot e^{\left(\left|n - m\right| + -1 \cdot \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(m - M\right)} \]
      6. cancel-sign-sub58.4%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|n - m\right| + -1 \cdot \ell\right) + M \cdot \left(m - M\right)}} \]
      7. neg-mul-158.4%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|\color{blue}{{\left(n - m\right)}^{1}}\right| - \ell\right) + M \cdot \left(m - M\right)} \]
      10. sqr-pow28.7%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{M \cdot \left(m - M\right) - \color{blue}{\left(m + \ell\right)}} \]
    16. Simplified79.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -7 \cdot 10^{+138}:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(M - n \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \left(m + \ell\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 49.0% accurate, 2.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.19999999999999954e-4

    1. Initial program 80.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*83.3%

        \[\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. +-commutative83.3%

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    11. Step-by-step derivation
      1. expm1-log1p-u24.4%

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

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

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

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

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

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

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

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

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

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

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

    if -5.19999999999999954e-4 < l

    1. Initial program 74.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*74.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. +-commutative74.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    11. Step-by-step derivation
      1. exp-neg40.8%

        \[\leadsto \cos M \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. un-div-inv40.8%

        \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    12. Applied egg-rr40.8%

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

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification48.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -0.00052:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 49.0% accurate, 2.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -9.2e-6

    1. Initial program 80.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*83.3%

        \[\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. +-commutative83.3%

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    11. Step-by-step derivation
      1. expm1-log1p-u24.4%

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

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

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

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

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

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

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

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

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

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

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

    if -9.2e-6 < l

    1. Initial program 74.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*74.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. +-commutative74.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    11. Step-by-step derivation
      1. exp-neg40.8%

        \[\leadsto \cos M \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      2. un-div-inv40.8%

        \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
    12. Applied egg-rr40.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -9.2 \cdot 10^{-6}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 34.7% accurate, 4.1× speedup?

\[\begin{array}{l} \\ \frac{1}{e^{\ell}} \end{array} \]
(FPCore (K m n M l) :precision binary64 (/ 1.0 (exp l)))
double code(double K, double m, double n, double M, double l) {
	return 1.0 / 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 = 1.0d0 / exp(l)
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0 / Math.exp(l);
}
def code(K, m, n, M, l):
	return 1.0 / math.exp(l)
function code(K, m, n, M, l)
	return Float64(1.0 / exp(l))
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0 / exp(l);
end
code[K_, m_, n_, M_, l_] := N[(1.0 / N[Exp[l], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{e^{\ell}}
\end{array}
Derivation
  1. Initial program 75.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  9. Step-by-step derivation
    1. mul-1-neg36.3%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  10. Simplified36.3%

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  11. Step-by-step derivation
    1. exp-neg36.3%

      \[\leadsto \cos M \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
    2. un-div-inv36.3%

      \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
  12. Applied egg-rr36.3%

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

    \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
  14. Final simplification36.3%

    \[\leadsto \frac{1}{e^{\ell}} \]
  15. Add Preprocessing

Alternative 14: 34.7% 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 75.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  9. Step-by-step derivation
    1. mul-1-neg36.3%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  10. Simplified36.3%

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

    \[\leadsto \color{blue}{e^{-\ell}} \]
  12. Final simplification36.3%

    \[\leadsto e^{-\ell} \]
  13. Add Preprocessing

Alternative 15: 7.2% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 75.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  9. Step-by-step derivation
    1. mul-1-neg36.3%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  10. Simplified36.3%

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

    \[\leadsto \color{blue}{\cos M} \]
  12. Final simplification5.4%

    \[\leadsto \cos M \]
  13. Add Preprocessing

Reproduce

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