Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.8% → 94.0%
Time: 18.0s
Alternatives: 8
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 8 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.8% 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: 94.0% accurate, 1.4× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} \mathbf{if}\;n \leq 5 \cdot 10^{+70}:\\ \;\;\;\;e^{\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot \left(M - m \cdot 0.5\right) + \left(\left|n - m\right| - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\ \end{array} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 5e+70)
   (exp (+ (* (+ n (- (* m 0.5) M)) (- M (* m 0.5))) (- (fabs (- n m)) l)))
   (* (cos M) (exp (* -0.25 (pow n 2.0))))))
assert(K < m && m < n && n < M && M < l);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 5e+70) {
		tmp = exp((((n + ((m * 0.5) - M)) * (M - (m * 0.5))) + (fabs((n - m)) - l)));
	} else {
		tmp = cos(M) * exp((-0.25 * pow(n, 2.0)));
	}
	return tmp;
}
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
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 (n <= 5d+70) then
        tmp = exp((((n + ((m * 0.5d0) - m_1)) * (m_1 - (m * 0.5d0))) + (abs((n - m)) - l)))
    else
        tmp = cos(m_1) * exp(((-0.25d0) * (n ** 2.0d0)))
    end if
    code = tmp
end function
assert K < m && m < n && n < M && M < l;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 5e+70) {
		tmp = Math.exp((((n + ((m * 0.5) - M)) * (M - (m * 0.5))) + (Math.abs((n - m)) - l)));
	} else {
		tmp = Math.cos(M) * Math.exp((-0.25 * Math.pow(n, 2.0)));
	}
	return tmp;
}
[K, m, n, M, l] = sort([K, m, n, M, l])
def code(K, m, n, M, l):
	tmp = 0
	if n <= 5e+70:
		tmp = math.exp((((n + ((m * 0.5) - M)) * (M - (m * 0.5))) + (math.fabs((n - m)) - l)))
	else:
		tmp = math.cos(M) * math.exp((-0.25 * math.pow(n, 2.0)))
	return tmp
K, m, n, M, l = sort([K, m, n, M, l])
function code(K, m, n, M, l)
	tmp = 0.0
	if (n <= 5e+70)
		tmp = exp(Float64(Float64(Float64(n + Float64(Float64(m * 0.5) - M)) * Float64(M - Float64(m * 0.5))) + Float64(abs(Float64(n - m)) - l)));
	else
		tmp = Float64(cos(M) * exp(Float64(-0.25 * (n ^ 2.0))));
	end
	return tmp
end
K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (n <= 5e+70)
		tmp = exp((((n + ((m * 0.5) - M)) * (M - (m * 0.5))) + (abs((n - m)) - l)));
	else
		tmp = cos(M) * exp((-0.25 * (n ^ 2.0)));
	end
	tmp_2 = tmp;
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 5e+70], N[Exp[N[(N[(N[(n + N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision] * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
\\
\begin{array}{l}
\mathbf{if}\;n \leq 5 \cdot 10^{+70}:\\
\;\;\;\;e^{\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot \left(M - m \cdot 0.5\right) + \left(\left|n - m\right| - \ell\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\


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

    1. Initial program 76.8%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative65.0%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow265.0%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified68.5%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 70.5%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*70.5%

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

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 82.9%

      \[\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|n - m\right|\right)} \]

    if 5.0000000000000002e70 < n

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification86.6%

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

Alternative 2: 96.6% accurate, 1.0× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \cos M \cdot e^{\left(\left|n - m\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (* (cos M) (exp (- (- (fabs (- n m)) l) (pow (- (/ (+ m n) 2.0) M) 2.0)))))
assert(K < m && m < n && n < M && M < l);
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)));
}
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
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
assert K < m && m < n && n < M && M < l;
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)));
}
[K, m, n, M, l] = sort([K, m, n, M, l])
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)))
K, m, n, M, l = sort([K, m, n, M, l])
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
K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp(((abs((n - m)) - l) - ((((m + n) / 2.0) - M) ^ 2.0)));
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
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}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, 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 76.7%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 81.0% accurate, 1.9× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := M - m \cdot 0.5\\ \mathbf{if}\;m \leq -7.2 \cdot 10^{+63}:\\ \;\;\;\;e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq 1.05 \cdot 10^{-108}:\\ \;\;\;\;e^{\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot t\_0 + \left(\left|n - m\right| - \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{n \cdot t\_0}\\ \end{array} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- M (* m 0.5))))
   (if (<= m -7.2e+63)
     (exp (* -0.25 (pow m 2.0)))
     (if (<= m 1.05e-108)
       (exp (+ (* (+ n (- (* m 0.5) M)) t_0) (- (fabs (- n m)) l)))
       (exp (* n t_0))))))
assert(K < m && m < n && n < M && M < l);
double code(double K, double m, double n, double M, double l) {
	double t_0 = M - (m * 0.5);
	double tmp;
	if (m <= -7.2e+63) {
		tmp = exp((-0.25 * pow(m, 2.0)));
	} else if (m <= 1.05e-108) {
		tmp = exp((((n + ((m * 0.5) - M)) * t_0) + (fabs((n - m)) - l)));
	} else {
		tmp = exp((n * t_0));
	}
	return tmp;
}
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: tmp
    t_0 = m_1 - (m * 0.5d0)
    if (m <= (-7.2d+63)) then
        tmp = exp(((-0.25d0) * (m ** 2.0d0)))
    else if (m <= 1.05d-108) then
        tmp = exp((((n + ((m * 0.5d0) - m_1)) * t_0) + (abs((n - m)) - l)))
    else
        tmp = exp((n * t_0))
    end if
    code = tmp
end function
assert K < m && m < n && n < M && M < l;
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = M - (m * 0.5);
	double tmp;
	if (m <= -7.2e+63) {
		tmp = Math.exp((-0.25 * Math.pow(m, 2.0)));
	} else if (m <= 1.05e-108) {
		tmp = Math.exp((((n + ((m * 0.5) - M)) * t_0) + (Math.abs((n - m)) - l)));
	} else {
		tmp = Math.exp((n * t_0));
	}
	return tmp;
}
[K, m, n, M, l] = sort([K, m, n, M, l])
def code(K, m, n, M, l):
	t_0 = M - (m * 0.5)
	tmp = 0
	if m <= -7.2e+63:
		tmp = math.exp((-0.25 * math.pow(m, 2.0)))
	elif m <= 1.05e-108:
		tmp = math.exp((((n + ((m * 0.5) - M)) * t_0) + (math.fabs((n - m)) - l)))
	else:
		tmp = math.exp((n * t_0))
	return tmp
K, m, n, M, l = sort([K, m, n, M, l])
function code(K, m, n, M, l)
	t_0 = Float64(M - Float64(m * 0.5))
	tmp = 0.0
	if (m <= -7.2e+63)
		tmp = exp(Float64(-0.25 * (m ^ 2.0)));
	elseif (m <= 1.05e-108)
		tmp = exp(Float64(Float64(Float64(n + Float64(Float64(m * 0.5) - M)) * t_0) + Float64(abs(Float64(n - m)) - l)));
	else
		tmp = exp(Float64(n * t_0));
	end
	return tmp
end
K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
function tmp_2 = code(K, m, n, M, l)
	t_0 = M - (m * 0.5);
	tmp = 0.0;
	if (m <= -7.2e+63)
		tmp = exp((-0.25 * (m ^ 2.0)));
	elseif (m <= 1.05e-108)
		tmp = exp((((n + ((m * 0.5) - M)) * t_0) + (abs((n - m)) - l)));
	else
		tmp = exp((n * t_0));
	end
	tmp_2 = tmp;
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[m, -7.2e+63], N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, 1.05e-108], N[Exp[N[(N[(N[(n + N[(N[(m * 0.5), $MachinePrecision] - M), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(n * t$95$0), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
\\
\begin{array}{l}
t_0 := M - m \cdot 0.5\\
\mathbf{if}\;m \leq -7.2 \cdot 10^{+63}:\\
\;\;\;\;e^{-0.25 \cdot {m}^{2}}\\

\mathbf{elif}\;m \leq 1.05 \cdot 10^{-108}:\\
\;\;\;\;e^{\left(n + \left(m \cdot 0.5 - M\right)\right) \cdot t\_0 + \left(\left|n - m\right| - \ell\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{n \cdot t\_0}\\


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

    1. Initial program 70.5%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative50.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow250.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out59.3%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative59.3%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative59.3%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified59.3%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 59.3%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.3%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified59.3%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 82.1%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in m around inf 97.8%

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

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified97.8%

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

    if -7.19999999999999998e63 < m < 1.05e-108

    1. Initial program 87.9%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative65.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow265.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out69.6%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative69.6%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative69.6%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified69.6%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 73.0%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*73.0%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified73.0%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 71.3%

      \[\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|n - m\right|\right)} \]

    if 1.05e-108 < m

    1. Initial program 66.8%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative51.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow251.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified56.9%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 59.0%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.0%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified59.0%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 83.2%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in n around inf 39.0%

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

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

Alternative 4: 81.7% accurate, 1.9× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -55:\\ \;\;\;\;e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq 3.15 \cdot 10^{-108}:\\ \;\;\;\;e^{M \cdot \left(n - M\right) - \left(\ell - \left|n - m\right|\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \end{array} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -55.0)
   (exp (* -0.25 (pow m 2.0)))
   (if (<= m 3.15e-108)
     (exp (- (* M (- n M)) (- l (fabs (- n m)))))
     (exp (* n (- M (* m 0.5)))))))
assert(K < m && m < n && n < M && M < l);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -55.0) {
		tmp = exp((-0.25 * pow(m, 2.0)));
	} else if (m <= 3.15e-108) {
		tmp = exp(((M * (n - M)) - (l - fabs((n - m)))));
	} else {
		tmp = exp((n * (M - (m * 0.5))));
	}
	return tmp;
}
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
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 <= (-55.0d0)) then
        tmp = exp(((-0.25d0) * (m ** 2.0d0)))
    else if (m <= 3.15d-108) then
        tmp = exp(((m_1 * (n - m_1)) - (l - abs((n - m)))))
    else
        tmp = exp((n * (m_1 - (m * 0.5d0))))
    end if
    code = tmp
end function
assert K < m && m < n && n < M && M < l;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -55.0) {
		tmp = Math.exp((-0.25 * Math.pow(m, 2.0)));
	} else if (m <= 3.15e-108) {
		tmp = Math.exp(((M * (n - M)) - (l - Math.abs((n - m)))));
	} else {
		tmp = Math.exp((n * (M - (m * 0.5))));
	}
	return tmp;
}
[K, m, n, M, l] = sort([K, m, n, M, l])
def code(K, m, n, M, l):
	tmp = 0
	if m <= -55.0:
		tmp = math.exp((-0.25 * math.pow(m, 2.0)))
	elif m <= 3.15e-108:
		tmp = math.exp(((M * (n - M)) - (l - math.fabs((n - m)))))
	else:
		tmp = math.exp((n * (M - (m * 0.5))))
	return tmp
K, m, n, M, l = sort([K, m, n, M, l])
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -55.0)
		tmp = exp(Float64(-0.25 * (m ^ 2.0)));
	elseif (m <= 3.15e-108)
		tmp = exp(Float64(Float64(M * Float64(n - M)) - Float64(l - abs(Float64(n - m)))));
	else
		tmp = exp(Float64(n * Float64(M - Float64(m * 0.5))));
	end
	return tmp
end
K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -55.0)
		tmp = exp((-0.25 * (m ^ 2.0)));
	elseif (m <= 3.15e-108)
		tmp = exp(((M * (n - M)) - (l - abs((n - m)))));
	else
		tmp = exp((n * (M - (m * 0.5))));
	end
	tmp_2 = tmp;
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -55.0], N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, 3.15e-108], N[Exp[N[(N[(M * N[(n - M), $MachinePrecision]), $MachinePrecision] - N[(l - N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(n * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
\\
\begin{array}{l}
\mathbf{if}\;m \leq -55:\\
\;\;\;\;e^{-0.25 \cdot {m}^{2}}\\

\mathbf{elif}\;m \leq 3.15 \cdot 10^{-108}:\\
\;\;\;\;e^{M \cdot \left(n - M\right) - \left(\ell - \left|n - m\right|\right)}\\

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


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

    1. Initial program 72.5%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative55.0%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow255.0%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out62.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative62.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative62.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified62.9%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 63.0%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*63.0%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified63.0%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 82.6%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in m around inf 98.1%

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

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified98.1%

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

    if -55 < m < 3.1499999999999999e-108

    1. Initial program 88.0%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative63.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow263.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified68.5%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 72.2%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*72.2%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified72.2%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 70.3%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in m around 0 70.3%

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

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

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

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

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

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

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

    if 3.1499999999999999e-108 < m

    1. Initial program 66.8%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative51.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow251.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified56.9%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 59.0%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.0%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified59.0%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 83.2%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in n around inf 39.0%

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

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

Alternative 5: 69.7% accurate, 1.9× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} t_0 := e^{-{M}^{2}}\\ \mathbf{if}\;M \leq -5:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq -2.1 \cdot 10^{-181}:\\ \;\;\;\;e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \mathbf{elif}\;M \leq 7.1 \cdot 10^{-43}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- (pow M 2.0)))))
   (if (<= M -5.0)
     t_0
     (if (<= M -2.1e-181)
       (exp (* n (- M (* m 0.5))))
       (if (<= M 7.1e-43) (exp (- l)) t_0)))))
assert(K < m && m < n && n < M && M < l);
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(-pow(M, 2.0));
	double tmp;
	if (M <= -5.0) {
		tmp = t_0;
	} else if (M <= -2.1e-181) {
		tmp = exp((n * (M - (m * 0.5))));
	} else if (M <= 7.1e-43) {
		tmp = exp(-l);
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
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(-(m_1 ** 2.0d0))
    if (m_1 <= (-5.0d0)) then
        tmp = t_0
    else if (m_1 <= (-2.1d-181)) then
        tmp = exp((n * (m_1 - (m * 0.5d0))))
    else if (m_1 <= 7.1d-43) then
        tmp = exp(-l)
    else
        tmp = t_0
    end if
    code = tmp
end function
assert K < m && m < n && n < M && M < l;
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(-Math.pow(M, 2.0));
	double tmp;
	if (M <= -5.0) {
		tmp = t_0;
	} else if (M <= -2.1e-181) {
		tmp = Math.exp((n * (M - (m * 0.5))));
	} else if (M <= 7.1e-43) {
		tmp = Math.exp(-l);
	} else {
		tmp = t_0;
	}
	return tmp;
}
[K, m, n, M, l] = sort([K, m, n, M, l])
def code(K, m, n, M, l):
	t_0 = math.exp(-math.pow(M, 2.0))
	tmp = 0
	if M <= -5.0:
		tmp = t_0
	elif M <= -2.1e-181:
		tmp = math.exp((n * (M - (m * 0.5))))
	elif M <= 7.1e-43:
		tmp = math.exp(-l)
	else:
		tmp = t_0
	return tmp
K, m, n, M, l = sort([K, m, n, M, l])
function code(K, m, n, M, l)
	t_0 = exp(Float64(-(M ^ 2.0)))
	tmp = 0.0
	if (M <= -5.0)
		tmp = t_0;
	elseif (M <= -2.1e-181)
		tmp = exp(Float64(n * Float64(M - Float64(m * 0.5))));
	elseif (M <= 7.1e-43)
		tmp = exp(Float64(-l));
	else
		tmp = t_0;
	end
	return tmp
end
K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(-(M ^ 2.0));
	tmp = 0.0;
	if (M <= -5.0)
		tmp = t_0;
	elseif (M <= -2.1e-181)
		tmp = exp((n * (M - (m * 0.5))));
	elseif (M <= 7.1e-43)
		tmp = exp(-l);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]}, If[LessEqual[M, -5.0], t$95$0, If[LessEqual[M, -2.1e-181], N[Exp[N[(n * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[M, 7.1e-43], N[Exp[(-l)], $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
\\
\begin{array}{l}
t_0 := e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -5:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -2.1 \cdot 10^{-181}:\\
\;\;\;\;e^{n \cdot \left(M - m \cdot 0.5\right)}\\

\mathbf{elif}\;M \leq 7.1 \cdot 10^{-43}:\\
\;\;\;\;e^{-\ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -5 or 7.10000000000000025e-43 < M

    1. Initial program 76.8%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative61.0%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow261.0%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out69.7%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative69.7%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative69.7%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified69.7%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 73.4%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*73.4%

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

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 86.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|n - m\right|\right)} \]
    12. Taylor expanded in M around inf 95.1%

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

        \[\leadsto 1 \cdot e^{\color{blue}{-{M}^{2}}} \]
    14. Simplified95.1%

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

    if -5 < M < -2.10000000000000003e-181

    1. Initial program 77.8%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative58.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow258.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out60.6%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative60.6%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative60.6%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified60.6%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 63.2%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*63.2%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified63.2%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 75.8%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in n around inf 44.0%

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

    if -2.10000000000000003e-181 < M < 7.10000000000000025e-43

    1. Initial program 76.0%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative50.7%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow250.7%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out52.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative52.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative52.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified52.1%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 51.9%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*51.9%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified51.9%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in l around inf 38.7%

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

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

      \[\leadsto \cos \left(\left(0.5 \cdot K\right) \cdot m\right) \cdot e^{\color{blue}{-\ell}} \]
    14. Taylor expanded in K around 0 42.7%

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

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

Alternative 6: 76.4% accurate, 2.0× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq 2.45 \cdot 10^{-108}:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \end{array} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -54.0)
   (exp (* -0.25 (pow m 2.0)))
   (if (<= m 2.45e-108) (exp (- (pow M 2.0))) (exp (* n (- M (* m 0.5)))))))
assert(K < m && m < n && n < M && M < l);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -54.0) {
		tmp = exp((-0.25 * pow(m, 2.0)));
	} else if (m <= 2.45e-108) {
		tmp = exp(-pow(M, 2.0));
	} else {
		tmp = exp((n * (M - (m * 0.5))));
	}
	return tmp;
}
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
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 <= (-54.0d0)) then
        tmp = exp(((-0.25d0) * (m ** 2.0d0)))
    else if (m <= 2.45d-108) then
        tmp = exp(-(m_1 ** 2.0d0))
    else
        tmp = exp((n * (m_1 - (m * 0.5d0))))
    end if
    code = tmp
end function
assert K < m && m < n && n < M && M < l;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -54.0) {
		tmp = Math.exp((-0.25 * Math.pow(m, 2.0)));
	} else if (m <= 2.45e-108) {
		tmp = Math.exp(-Math.pow(M, 2.0));
	} else {
		tmp = Math.exp((n * (M - (m * 0.5))));
	}
	return tmp;
}
[K, m, n, M, l] = sort([K, m, n, M, l])
def code(K, m, n, M, l):
	tmp = 0
	if m <= -54.0:
		tmp = math.exp((-0.25 * math.pow(m, 2.0)))
	elif m <= 2.45e-108:
		tmp = math.exp(-math.pow(M, 2.0))
	else:
		tmp = math.exp((n * (M - (m * 0.5))))
	return tmp
K, m, n, M, l = sort([K, m, n, M, l])
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -54.0)
		tmp = exp(Float64(-0.25 * (m ^ 2.0)));
	elseif (m <= 2.45e-108)
		tmp = exp(Float64(-(M ^ 2.0)));
	else
		tmp = exp(Float64(n * Float64(M - Float64(m * 0.5))));
	end
	return tmp
end
K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -54.0)
		tmp = exp((-0.25 * (m ^ 2.0)));
	elseif (m <= 2.45e-108)
		tmp = exp(-(M ^ 2.0));
	else
		tmp = exp((n * (M - (m * 0.5))));
	end
	tmp_2 = tmp;
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -54.0], N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, 2.45e-108], N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision], N[Exp[N[(n * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
\\
\begin{array}{l}
\mathbf{if}\;m \leq -54:\\
\;\;\;\;e^{-0.25 \cdot {m}^{2}}\\

\mathbf{elif}\;m \leq 2.45 \cdot 10^{-108}:\\
\;\;\;\;e^{-{M}^{2}}\\

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


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

    1. Initial program 72.5%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative55.0%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow255.0%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out62.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative62.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative62.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified62.9%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 63.0%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*63.0%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified63.0%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 82.6%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in m around inf 98.1%

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

        \[\leadsto 1 \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    14. Simplified98.1%

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

    if -54 < m < 2.4499999999999999e-108

    1. Initial program 88.0%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative63.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow263.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative68.5%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified68.5%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 72.2%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*72.2%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified72.2%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 70.3%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in M around inf 66.1%

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

        \[\leadsto 1 \cdot e^{\color{blue}{-{M}^{2}}} \]
    14. Simplified66.1%

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

    if 2.4499999999999999e-108 < m

    1. Initial program 66.8%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative51.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow251.8%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative56.9%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified56.9%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 59.0%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*59.0%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified59.0%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 83.2%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in n around inf 39.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;m \leq 2.45 \cdot 10^{-108}:\\ \;\;\;\;e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 54.2% accurate, 3.5× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.5 \cdot 10^{+269} \lor \neg \left(\ell \leq -1.95 \cdot 10^{+231}\right) \land \ell \leq 700:\\ \;\;\;\;e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l)
 :precision binary64
 (if (or (<= l -5.5e+269) (and (not (<= l -1.95e+231)) (<= l 700.0)))
   (exp (* n (- M (* m 0.5))))
   (exp (- l))))
assert(K < m && m < n && n < M && M < l);
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((l <= -5.5e+269) || (!(l <= -1.95e+231) && (l <= 700.0))) {
		tmp = exp((n * (M - (m * 0.5))));
	} else {
		tmp = exp(-l);
	}
	return tmp;
}
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
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 <= (-5.5d+269)) .or. (.not. (l <= (-1.95d+231))) .and. (l <= 700.0d0)) then
        tmp = exp((n * (m_1 - (m * 0.5d0))))
    else
        tmp = exp(-l)
    end if
    code = tmp
end function
assert K < m && m < n && n < M && M < l;
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((l <= -5.5e+269) || (!(l <= -1.95e+231) && (l <= 700.0))) {
		tmp = Math.exp((n * (M - (m * 0.5))));
	} else {
		tmp = Math.exp(-l);
	}
	return tmp;
}
[K, m, n, M, l] = sort([K, m, n, M, l])
def code(K, m, n, M, l):
	tmp = 0
	if (l <= -5.5e+269) or (not (l <= -1.95e+231) and (l <= 700.0)):
		tmp = math.exp((n * (M - (m * 0.5))))
	else:
		tmp = math.exp(-l)
	return tmp
K, m, n, M, l = sort([K, m, n, M, l])
function code(K, m, n, M, l)
	tmp = 0.0
	if ((l <= -5.5e+269) || (!(l <= -1.95e+231) && (l <= 700.0)))
		tmp = exp(Float64(n * Float64(M - Float64(m * 0.5))));
	else
		tmp = exp(Float64(-l));
	end
	return tmp
end
K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if ((l <= -5.5e+269) || (~((l <= -1.95e+231)) && (l <= 700.0)))
		tmp = exp((n * (M - (m * 0.5))));
	else
		tmp = exp(-l);
	end
	tmp_2 = tmp;
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[l, -5.5e+269], And[N[Not[LessEqual[l, -1.95e+231]], $MachinePrecision], LessEqual[l, 700.0]]], N[Exp[N[(n * N[(M - N[(m * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[(-l)], $MachinePrecision]]
\begin{array}{l}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.5 \cdot 10^{+269} \lor \neg \left(\ell \leq -1.95 \cdot 10^{+231}\right) \land \ell \leq 700:\\
\;\;\;\;e^{n \cdot \left(M - m \cdot 0.5\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.50000000000000026e269 or -1.9500000000000001e231 < l < 700

    1. Initial program 75.8%

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

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative55.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow255.1%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out61.4%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative61.4%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative61.4%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified61.4%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 63.0%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*63.0%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified63.0%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in K around 0 75.5%

      \[\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|n - m\right|\right)} \]
    12. Taylor expanded in n around inf 43.0%

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

    if -5.50000000000000026e269 < l < -1.9500000000000001e231 or 700 < 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. Step-by-step derivation
      1. associate-/l*79.7%

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

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

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

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

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

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    6. Step-by-step derivation
      1. +-commutative64.2%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      2. unpow264.2%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      3. distribute-rgt-out67.4%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      4. *-commutative67.4%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
      5. *-commutative67.4%

        \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    7. Simplified67.4%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    8. Taylor expanded in m around inf 72.1%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
    9. Step-by-step derivation
      1. associate-*r*72.1%

        \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    10. Simplified72.1%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
    11. Taylor expanded in l around inf 79.8%

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

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

      \[\leadsto \cos \left(\left(0.5 \cdot K\right) \cdot m\right) \cdot e^{\color{blue}{-\ell}} \]
    14. Taylor expanded in K around 0 90.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.5 \cdot 10^{+269} \lor \neg \left(\ell \leq -1.95 \cdot 10^{+231}\right) \land \ell \leq 700:\\ \;\;\;\;e^{n \cdot \left(M - m \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 35.5% accurate, 4.2× speedup?

\[\begin{array}{l} [K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\ \\ e^{-\ell} \end{array} \]
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
(FPCore (K m n M l) :precision binary64 (exp (- l)))
assert(K < m && m < n && n < M && M < l);
double code(double K, double m, double n, double M, double l) {
	return exp(-l);
}
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = exp(-l)
end function
assert K < m && m < n && n < M && M < l;
public static double code(double K, double m, double n, double M, double l) {
	return Math.exp(-l);
}
[K, m, n, M, l] = sort([K, m, n, M, l])
def code(K, m, n, M, l):
	return math.exp(-l)
K, m, n, M, l = sort([K, m, n, M, l])
function code(K, m, n, M, l)
	return exp(Float64(-l))
end
K, m, n, M, l = num2cell(sort([K, m, n, M, l])){:}
function tmp = code(K, m, n, M, l)
	tmp = exp(-l);
end
NOTE: K, m, n, M, and l should be sorted in increasing order before calling this function.
code[K_, m_, n_, M_, l_] := N[Exp[(-l)], $MachinePrecision]
\begin{array}{l}
[K, m, n, M, l] = \mathsf{sort}([K, m, n, M, l])\\
\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 76.7%

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

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

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

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

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

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

    \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
  6. Step-by-step derivation
    1. +-commutative57.4%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    2. unpow257.4%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    3. distribute-rgt-out62.9%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    4. *-commutative62.9%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
    5. *-commutative62.9%

      \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
  7. Simplified62.9%

    \[\leadsto \cos \left(\frac{K}{\frac{2}{m + n}} - 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|n - m\right|\right)} \]
  8. Taylor expanded in m around inf 65.2%

    \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\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|n - m\right|\right)} \]
  9. Step-by-step derivation
    1. associate-*r*65.2%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
  10. Simplified65.2%

    \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\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|n - m\right|\right)} \]
  11. Taylor expanded in l around inf 29.4%

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

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

    \[\leadsto \cos \left(\left(0.5 \cdot K\right) \cdot m\right) \cdot e^{\color{blue}{-\ell}} \]
  14. Taylor expanded in K around 0 31.6%

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

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

Reproduce

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