Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.0% → 96.5%
Time: 19.6s
Alternatives: 11
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 11 alternatives:

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

Initial Program: 76.0% accurate, 1.0× speedup?

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

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

Alternative 1: 96.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(M \cdot \left(0.5 \cdot \frac{m + n}{M} + -1\right)\right)}^{2}} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (*
  (cos M)
  (exp
   (- (- (fabs (- m n)) l) (pow (* M (+ (* 0.5 (/ (+ m n) M)) -1.0)) 2.0)))))
double code(double K, double m, double n, double M, double l) {
	return cos(M) * exp(((fabs((m - n)) - l) - pow((M * ((0.5 * ((m + n) / M)) + -1.0)), 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_1 * ((0.5d0 * ((m + n) / m_1)) + (-1.0d0))) ** 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 * ((0.5 * ((m + n) / M)) + -1.0)), 2.0)));
}
def code(K, m, n, M, l):
	return math.cos(M) * math.exp(((math.fabs((m - n)) - l) - math.pow((M * ((0.5 * ((m + n) / M)) + -1.0)), 2.0)))
function code(K, m, n, M, l)
	return Float64(cos(M) * exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(M * Float64(Float64(0.5 * Float64(Float64(m + n) / M)) + -1.0)) ^ 2.0))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp(((abs((m - n)) - l) - ((M * ((0.5 * ((m + n) / M)) + -1.0)) ^ 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[(M * N[(N[(0.5 * N[(N[(m + n), $MachinePrecision] / M), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(M \cdot \left(0.5 \cdot \frac{m + n}{M} + -1\right)\right)}^{2}}
\end{array}
Derivation
  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. Add Preprocessing
  3. Taylor expanded in K around 0 96.5%

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

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

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

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

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

Alternative 2: 96.2% 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 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. Add Preprocessing
  3. Taylor expanded in m around inf 85.7%

    \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\right)\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. *-commutative85.7%

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

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

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

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

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

Alternative 3: 86.5% accurate, 1.4× speedup?

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

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


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

    1. Initial program 69.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 n around 0 58.1%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{-0.25 \cdot {m}^{2}} \]
    8. Step-by-step derivation
      1. cos-neg98.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)} \]
    9. Simplified98.4%

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

    if -5.09999999999999973e36 < 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. Add Preprocessing
    3. Taylor expanded in m around inf 90.4%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\right)\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. *-commutative90.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 64.0% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -1.8 \cdot 10^{+17} \lor \neg \left(m \leq 0.082\right):\\
\;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{-\ell} \cdot \sin M\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -1.8e17 or 0.0820000000000000034 < m

    1. Initial program 72.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. Add Preprocessing
    3. Taylor expanded in n around 0 61.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*89.1%

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

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

    if -1.8e17 < m < 0.0820000000000000034

    1. Initial program 86.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 n around 0 64.8%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\left|m - n\right| - \left(\ell + \left(0.5 \cdot m - M\right) \cdot \left(\left(n + 0.5 \cdot m\right) - M\right)\right)} \cdot \sin M\right)\right)\right)} \]
    10. Taylor expanded in l around inf 48.4%

      \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{-1 \cdot \ell}} \cdot \sin M\right)\right)\right) \]
    11. Step-by-step derivation
      1. neg-mul-148.4%

        \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{-\ell}} \cdot \sin M\right)\right)\right) \]
    12. Simplified48.4%

      \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{-\ell}} \cdot \sin M\right)\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1.8 \cdot 10^{+17} \lor \neg \left(m \leq 0.082\right):\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{-\ell} \cdot \sin M\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 51.7% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -1.8 \cdot 10^{+17}:\\
\;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\

\mathbf{elif}\;m \leq -1.5 \cdot 10^{-300}:\\
\;\;\;\;e^{-\ell} \cdot \cos \left(\left(0.5 \cdot m\right) \cdot K\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{n \cdot \left(M - 0.5 \cdot m\right)} \cdot \sin M\right)\right)\right)\\


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

    1. Initial program 70.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.5 \cdot \left(m \cdot \left(n + 0.5 \cdot m\right)\right)} \]
      3. associate-*r*91.5%

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

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

    if -1.8e17 < m < -1.50000000000000012e-300

    1. Initial program 92.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 n around 0 68.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.50000000000000012e-300 < m

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in n around 0 62.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{n \cdot \left(M - 0.5 \cdot m\right)}} \cdot \sin M\right)\right)\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification55.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1.8 \cdot 10^{+17}:\\ \;\;\;\;e^{\left(\left|m - n\right| - \ell\right) - \left(0.5 \cdot m\right) \cdot \left(n + 0.5 \cdot m\right)}\\ \mathbf{elif}\;m \leq -1.5 \cdot 10^{-300}:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(\left(0.5 \cdot m\right) \cdot K\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{n \cdot \left(M - 0.5 \cdot m\right)} \cdot \sin M\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 84.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right| - \ell\\ \mathbf{if}\;m \leq -4 \cdot 10^{+84}:\\ \;\;\;\;e^{\left(0.5 \cdot m - M\right) \cdot \left(\left(M - 0.5 \cdot m\right) - n\right) + t\_0}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(0.5 \cdot n - M\right) \cdot \left(\left(M - 0.5 \cdot n\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 -4e+84)
     (exp (+ (* (- (* 0.5 m) M) (- (- M (* 0.5 m)) n)) t_0))
     (exp (+ (* (- (* 0.5 n) M) (- (- M (* 0.5 n)) 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 <= -4e+84) {
		tmp = exp(((((0.5 * m) - M) * ((M - (0.5 * m)) - n)) + t_0));
	} else {
		tmp = exp(((((0.5 * n) - M) * ((M - (0.5 * n)) - 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 <= (-4d+84)) then
        tmp = exp(((((0.5d0 * m) - m_1) * ((m_1 - (0.5d0 * m)) - n)) + t_0))
    else
        tmp = exp(((((0.5d0 * n) - m_1) * ((m_1 - (0.5d0 * n)) - 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 <= -4e+84) {
		tmp = Math.exp(((((0.5 * m) - M) * ((M - (0.5 * m)) - n)) + t_0));
	} else {
		tmp = Math.exp(((((0.5 * n) - M) * ((M - (0.5 * n)) - m)) + t_0));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.fabs((m - n)) - l
	tmp = 0
	if m <= -4e+84:
		tmp = math.exp(((((0.5 * m) - M) * ((M - (0.5 * m)) - n)) + t_0))
	else:
		tmp = math.exp(((((0.5 * n) - M) * ((M - (0.5 * n)) - 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 <= -4e+84)
		tmp = exp(Float64(Float64(Float64(Float64(0.5 * m) - M) * Float64(Float64(M - Float64(0.5 * m)) - n)) + t_0));
	else
		tmp = exp(Float64(Float64(Float64(Float64(0.5 * n) - M) * Float64(Float64(M - Float64(0.5 * n)) - 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 <= -4e+84)
		tmp = exp(((((0.5 * m) - M) * ((M - (0.5 * m)) - n)) + t_0));
	else
		tmp = exp(((((0.5 * n) - M) * ((M - (0.5 * n)) - 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, -4e+84], N[Exp[N[(N[(N[(N[(0.5 * m), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - N[(0.5 * m), $MachinePrecision]), $MachinePrecision] - n), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision], N[Exp[N[(N[(N[(N[(0.5 * n), $MachinePrecision] - M), $MachinePrecision] * N[(N[(M - N[(0.5 * n), $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 -4 \cdot 10^{+84}:\\
\;\;\;\;e^{\left(0.5 \cdot m - M\right) \cdot \left(\left(M - 0.5 \cdot m\right) - n\right) + t\_0}\\

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


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

    1. Initial program 69.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 n around 0 59.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.00000000000000023e84 < m

    1. Initial program 81.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 m around inf 89.6%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\right)\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. *-commutative89.6%

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 81.3% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 78.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. Add Preprocessing
    3. Taylor expanded in n around 0 60.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.11999999999999998e-4 < l

    1. Initial program 79.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 n around 0 68.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 39.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
\mathbf{if}\;\ell \leq -6.4 \cdot 10^{-34}:\\
\;\;\;\;t\_0 \cdot \cos \left(\frac{1}{\frac{2}{\left(m + n\right) \cdot K}} - M\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(t\_0 \cdot \sin M\right)\right)\right)\\


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

    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 n around 0 60.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.40000000000000005e-34 < l

    1. Initial program 81.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. Add Preprocessing
    3. Taylor expanded in n around 0 63.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\left|m - n\right| - \left(\ell + \left(0.5 \cdot m - M\right) \cdot \left(\left(n + 0.5 \cdot m\right) - M\right)\right)} \cdot \sin M\right)\right)\right)} \]
    10. Taylor expanded in l around inf 48.0%

      \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{-1 \cdot \ell}} \cdot \sin M\right)\right)\right) \]
    11. Step-by-step derivation
      1. neg-mul-148.0%

        \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{-\ell}} \cdot \sin M\right)\right)\right) \]
    12. Simplified48.0%

      \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{-\ell}} \cdot \sin M\right)\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification40.7%

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

Alternative 9: 39.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
\mathbf{if}\;\ell \leq -5 \cdot 10^{-34}:\\
\;\;\;\;t\_0 \cdot \cos \left(\left(0.5 \cdot n\right) \cdot K\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(t\_0 \cdot \sin M\right)\right)\right)\\


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

    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 n around 0 60.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.0000000000000003e-34 < l

    1. Initial program 81.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. Add Preprocessing
    3. Taylor expanded in n around 0 63.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\left|m - n\right| - \left(\ell + \left(0.5 \cdot m - M\right) \cdot \left(\left(n + 0.5 \cdot m\right) - M\right)\right)} \cdot \sin M\right)\right)\right)} \]
    10. Taylor expanded in l around inf 48.0%

      \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{-1 \cdot \ell}} \cdot \sin M\right)\right)\right) \]
    11. Step-by-step derivation
      1. neg-mul-148.0%

        \[\leadsto 0.5 \cdot \left(K \cdot \left(m \cdot \left(e^{\color{blue}{-\ell}} \cdot \sin M\right)\right)\right) \]
    12. Simplified48.0%

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

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

Alternative 10: 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 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. Add Preprocessing
  3. Taylor expanded in n around 0 62.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 7.0% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 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. Add Preprocessing
  3. Taylor expanded in n around 0 62.8%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \]
  12. Simplified6.5%

    \[\leadsto \color{blue}{\cos M} \]
  13. Add Preprocessing

Reproduce

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