Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.1% → 96.7%
Time: 25.1s
Alternatives: 9
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 76.1% accurate, 1.0× speedup?

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

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

Alternative 1: 96.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 2: 96.2% accurate, 1.4× speedup?

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

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

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in m around inf 81.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. *-commutative81.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*81.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. Simplified81.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 97.0%

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

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

Alternative 3: 85.9% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 71.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.0%

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

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

        \[\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.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. *-commutative65.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. *-commutative65.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. Simplified65.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 n around inf 81.5%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot n\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. *-commutative81.5%

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

        \[\leadsto \cos \color{blue}{\left(K \cdot \left(n \cdot 0.5\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. Simplified81.5%

      \[\leadsto \cos \color{blue}{\left(K \cdot \left(n \cdot 0.5\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 K around 0 86.5%

      \[\leadsto \color{blue}{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)}} \]

    if 2e20 < n

    1. Initial program 72.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 95.1%

      \[\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. *-commutative95.1%

        \[\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*95.1%

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

      \[\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 m around 0 95.2%

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

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

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

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

Alternative 4: 74.2% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \left|n - m\right|\\
\mathbf{if}\;M \leq -0.27 \lor \neg \left(M \leq 2 \cdot 10^{+85}\right):\\
\;\;\;\;e^{t\_0 + \left(M \cdot \left(n - M\right) - \ell\right)}\\

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


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

    1. Initial program 74.3%

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

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

        \[\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*84.1%

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

      \[\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 m around 0 95.6%

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

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

        \[\leadsto e^{\left|m - n\right| - \left(\ell + \left(\color{blue}{\left(-M \cdot n\right)} + {M}^{2}\right)\right)} \]
      2. distribute-rgt-neg-in82.5%

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

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

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

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

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

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

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

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

    if -0.27000000000000002 < M < 2e85

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

      \[\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. *-commutative79.3%

        \[\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*79.3%

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

      \[\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 m around 0 69.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 60.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
t_0 := \left|n - m\right|\\
\mathbf{if}\;n \leq -8 \cdot 10^{-95}:\\
\;\;\;\;\cos \left(\left(n \cdot 0.5\right) \cdot K\right) \cdot e^{n \cdot \left(M - m \cdot 0.5\right)}\\

\mathbf{elif}\;n \leq 4.8 \cdot 10^{+47}:\\
\;\;\;\;e^{t\_0 + \left(M \cdot \left(n - M\right) - \ell\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < -7.99999999999999992e-95

    1. Initial program 67.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 49.0%

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

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

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

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

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

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

      \[\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 n around inf 67.6%

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

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

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

      \[\leadsto \cos \color{blue}{\left(K \cdot \left(n \cdot 0.5\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 n around inf 36.9%

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

    if -7.99999999999999992e-95 < n < 4.80000000000000037e47

    1. Initial program 75.1%

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

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

        \[\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*75.8%

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

      \[\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 m around 0 71.8%

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

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

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

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

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

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

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

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

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

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

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

    if 4.80000000000000037e47 < n

    1. Initial program 69.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 m around inf 94.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. *-commutative94.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*94.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. Simplified94.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 m around 0 94.7%

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

        \[\leadsto e^{\left|m - n\right| - \left(\ell + \color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)}\right)} \]
    8. Applied egg-rr94.7%

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

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

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

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

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

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

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

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

        \[\leadsto e^{\left|m - n\right| - \left(\ell + \left(\left(-\color{blue}{n \cdot M}\right) + n \cdot \left(0.25 \cdot n\right)\right)\right)} \]
      8. distribute-rgt-neg-in78.8%

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

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

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

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

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

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

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

Alternative 6: 58.7% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1300000000 \lor \neg \left(\ell \leq 7 \cdot 10^{+180}\right):\\
\;\;\;\;e^{\left|n - m\right| + \left(M \cdot \left(n - M\right) - \ell\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(\left(n \cdot 0.5\right) \cdot K\right) \cdot e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.3e9 or 6.9999999999999996e180 < l

    1. Initial program 70.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 80.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. *-commutative80.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*80.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. Simplified80.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 m around 0 79.4%

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

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

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

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

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

        \[\leadsto e^{\left|m - n\right| - \left(\ell + \left(M \cdot \left(-1 \cdot n\right) + \color{blue}{M \cdot M}\right)\right)} \]
      5. distribute-lft-in54.7%

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

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

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

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

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

    if 1.3e9 < l < 6.9999999999999996e180

    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 72.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. +-commutative72.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. unpow272.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-out75.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. *-commutative75.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. *-commutative75.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. Simplified75.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 n around inf 84.9%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot n\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. *-commutative84.9%

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

        \[\leadsto \cos \color{blue}{\left(K \cdot \left(n \cdot 0.5\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. Simplified84.9%

      \[\leadsto \cos \color{blue}{\left(K \cdot \left(n \cdot 0.5\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 l around inf 87.9%

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

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

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

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

Alternative 7: 79.8% accurate, 2.0× speedup?

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

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

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

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

      \[\leadsto e^{\left|m - n\right| - \left(\ell + \color{blue}{\left(0.5 \cdot n - M\right) \cdot \left(0.5 \cdot n - M\right)}\right)} \]
  8. Applied egg-rr81.3%

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

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

Alternative 8: 31.4% accurate, 2.0× speedup?

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

\\
\cos \left(\left(n \cdot 0.5\right) \cdot K\right) \cdot e^{-\ell}
\end{array}
Derivation
  1. Initial program 71.3%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in n around 0 58.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. +-commutative58.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. unpow258.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-out61.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. *-commutative61.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. *-commutative61.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. Simplified61.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 n around inf 73.5%

    \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot n\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. *-commutative73.5%

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

      \[\leadsto \cos \color{blue}{\left(K \cdot \left(n \cdot 0.5\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.5%

    \[\leadsto \cos \color{blue}{\left(K \cdot \left(n \cdot 0.5\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 l around inf 31.3%

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

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

    \[\leadsto \cos \left(K \cdot \left(n \cdot 0.5\right)\right) \cdot e^{\color{blue}{-\ell}} \]
  12. Final simplification31.3%

    \[\leadsto \cos \left(\left(n \cdot 0.5\right) \cdot K\right) \cdot e^{-\ell} \]
  13. Add Preprocessing

Alternative 9: 24.3% accurate, 2.1× speedup?

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

\\
e^{\left|n - m\right| - \ell}
\end{array}
Derivation
  1. Initial program 71.3%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in m around inf 81.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. *-commutative81.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*81.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. Simplified81.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 97.0%

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

    \[\leadsto e^{\left|m - n\right| - \color{blue}{\ell}} \]
  8. Final simplification27.1%

    \[\leadsto e^{\left|n - m\right| - \ell} \]
  9. Add Preprocessing

Reproduce

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