Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.7% → 96.9%
Time: 25.7s
Alternatives: 9
Speedup: 1.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 76.7% accurate, 1.0× speedup?

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

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

Alternative 1: 96.9% accurate, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 2: 96.4% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

Alternative 3: 87.3% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 68.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. Add Preprocessing
    3. Taylor expanded in K around 0 96.7%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      6. associate-*l*80.1%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      8. distribute-lft-out--88.5%

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

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

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

    if -12500 < m

    1. Initial program 74.4%

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

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

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

      \[\leadsto 1 \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)} \]
    8. Step-by-step derivation
      1. +-commutative76.9%

        \[\leadsto 1 \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|m - n\right|\right)} \]
      2. unpow276.9%

        \[\leadsto 1 \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|m - n\right|\right)} \]
      3. distribute-rgt-out82.5%

        \[\leadsto 1 \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|m - n\right|\right)} \]
      4. *-commutative82.5%

        \[\leadsto 1 \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|m - n\right|\right)} \]
      5. *-commutative82.5%

        \[\leadsto 1 \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|m - n\right|\right)} \]
    9. Simplified82.5%

      \[\leadsto 1 \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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.8%

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

Alternative 4: 85.2% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ \mathbf{if}\;m \leq -6900:\\ \;\;\;\;e^{\left(m + n\right) \cdot \left(M - \left(m + n\right) \cdot 0.25\right) + t\_0}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(n \cdot 0.5 - M\right) \cdot \left(\left(M - n \cdot 0.5\right) - m\right) + t\_0}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (fabs (- m n)) l)))
   (if (<= m -6900.0)
     (exp (+ (* (+ m n) (- M (* (+ m n) 0.25))) t_0))
     (exp (+ (* (- (* n 0.5) M) (- (- M (* n 0.5)) m)) t_0)))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n)) - l;
	double tmp;
	if (m <= -6900.0) {
		tmp = exp((((m + n) * (M - ((m + n) * 0.25))) + t_0));
	} else {
		tmp = exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) + t_0));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: tmp
    t_0 = abs((m - n)) - l
    if (m <= (-6900.0d0)) then
        tmp = exp((((m + n) * (m_1 - ((m + n) * 0.25d0))) + t_0))
    else
        tmp = exp(((((n * 0.5d0) - m_1) * ((m_1 - (n * 0.5d0)) - m)) + 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.abs((m - n)) - l;
	double tmp;
	if (m <= -6900.0) {
		tmp = Math.exp((((m + n) * (M - ((m + n) * 0.25))) + t_0));
	} else {
		tmp = Math.exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) + t_0));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n)) - l
	tmp = 0
	if m <= -6900.0:
		tmp = math.exp((((m + n) * (M - ((m + n) * 0.25))) + t_0))
	else:
		tmp = math.exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) + t_0))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(abs(Float64(m - n)) - l)
	tmp = 0.0
	if (m <= -6900.0)
		tmp = exp(Float64(Float64(Float64(m + n) * Float64(M - Float64(Float64(m + n) * 0.25))) + t_0));
	else
		tmp = exp(Float64(Float64(Float64(Float64(n * 0.5) - M) * Float64(Float64(M - Float64(n * 0.5)) - m)) + t_0));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = abs((m - n)) - l;
	tmp = 0.0;
	if (m <= -6900.0)
		tmp = exp((((m + n) * (M - ((m + n) * 0.25))) + t_0));
	else
		tmp = exp(((((n * 0.5) - M) * ((M - (n * 0.5)) - m)) + t_0));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]}, If[LessEqual[m, -6900.0], N[Exp[N[(N[(N[(m + n), $MachinePrecision] * N[(M - N[(N[(m + n), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $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] + t$95$0), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

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

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


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

    1. Initial program 68.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. Add Preprocessing
    3. Taylor expanded in K around 0 96.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      6. associate-*l*80.1%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      8. distribute-lft-out--88.5%

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

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

    if -6900 < m

    1. Initial program 74.4%

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

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

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

      \[\leadsto 1 \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)} \]
    8. Step-by-step derivation
      1. +-commutative76.9%

        \[\leadsto 1 \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|m - n\right|\right)} \]
      2. unpow276.9%

        \[\leadsto 1 \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|m - n\right|\right)} \]
      3. distribute-rgt-out82.5%

        \[\leadsto 1 \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|m - n\right|\right)} \]
      4. *-commutative82.5%

        \[\leadsto 1 \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|m - n\right|\right)} \]
      5. *-commutative82.5%

        \[\leadsto 1 \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|m - n\right|\right)} \]
    9. Simplified82.5%

      \[\leadsto 1 \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)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.9%

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

Alternative 5: 54.0% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.5 \cdot 10^{+108} \lor \neg \left(\ell \leq -7 \cdot 10^{+34}\right) \land \ell \leq 1.8:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(m + n\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.49999999999999992e108 or -6.99999999999999996e34 < l < 1.80000000000000004

    1. Initial program 73.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 K around 0 93.8%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      6. associate-*l*73.2%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      8. distribute-lft-out--78.4%

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

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

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

    if -1.49999999999999992e108 < l < -6.99999999999999996e34 or 1.80000000000000004 < l

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      6. associate-*l*87.0%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      8. distribute-lft-out--89.5%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    11. Simplified88.3%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.5%

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

Alternative 6: 84.1% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 2:\\
\;\;\;\;e^{\left(m + n\right) \cdot \left(M - \left(m + n\right) \cdot 0.25\right) + \left(\left|m - n\right| - \ell\right)}\\

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


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

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      6. associate-*l*75.1%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      8. distribute-lft-out--79.8%

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

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

    if 2 < l

    1. Initial program 67.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. Add Preprocessing
    3. Taylor expanded in K around 0 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      6. associate-*l*85.2%

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

        \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      8. distribute-lft-out--88.2%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    11. Simplified100.0%

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

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

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

Alternative 7: 36.5% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{-\ell} \end{array} \]
(FPCore (K m n M l) :precision binary64 (* (cos M) (exp (- l))))
double code(double K, double m, double n, double M, double l) {
	return cos(M) * 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 = cos(m_1) * exp(-l)
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M) * Math.exp(-l);
}
def code(K, m, n, M, l):
	return math.cos(M) * math.exp(-l)
function code(K, m, n, M, l)
	return Float64(cos(M) * exp(Float64(-l)))
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp(-l);
end
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos M \cdot e^{-\ell}
\end{array}
Derivation
  1. Initial program 73.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    6. associate-*l*77.7%

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

      \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    8. distribute-lft-out--82.0%

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  12. Final simplification39.8%

    \[\leadsto \cos M \cdot e^{-\ell} \]
  13. Add Preprocessing

Alternative 8: 36.0% 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 73.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    6. associate-*l*77.7%

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

      \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    8. distribute-lft-out--82.0%

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

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

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

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

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

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

    \[\leadsto e^{-\ell} \]
  14. Add Preprocessing

Alternative 9: 7.1% 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 73.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(-\left(\color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)} \cdot 0.25 - M \cdot \left(m + n\right)\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    6. associate-*l*77.7%

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

      \[\leadsto \cos M \cdot e^{\left(-\left(\left(m + n\right) \cdot \left(\left(m + n\right) \cdot 0.25\right) - \color{blue}{\left(m + n\right) \cdot M}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    8. distribute-lft-out--82.0%

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

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

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

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

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

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

    \[\leadsto \cos M \]
  14. Add Preprocessing

Reproduce

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