Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.4% → 96.4%
Time: 21.9s
Alternatives: 10
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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

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

Alternative 1: 96.4% accurate, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 2: 74.3% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -1.15 \cdot 10^{+76} \lor \neg \left(M \leq 5 \cdot 10^{+58}\right):\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -1.15000000000000001e76 or 4.99999999999999986e58 < M

    1. Initial program 73.1%

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

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

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

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

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

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

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

    if -1.15000000000000001e76 < M < 4.99999999999999986e58

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 74.7% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 53.1%

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

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

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

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

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

    if -2.4999999999999998e22 < m

    1. Initial program 79.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 71.6% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 47.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999997e106 < m

    1. Initial program 78.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 71.1% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 46.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000018e106 < m

    1. Initial program 78.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\left|m - n\right| - \left(\ell + \left(-M \cdot \color{blue}{\left(m + \left(n - M\right)\right)}\right)\right)} \]
      3. distribute-lft-neg-in59.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 68.8% accurate, 3.7× speedup?

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

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

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


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

    1. Initial program 73.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.85e-4 < l

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

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

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

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

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

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

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

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

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

Alternative 7: 69.5% accurate, 3.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto e^{\color{blue}{\left(m - \left(n + \ell\right)\right)} + M \cdot \left(m + \left(n - M\right)\right)} \]
  16. Final simplification73.1%

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

Alternative 8: 35.9% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 73.1%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{e^{-\ell}} \]
  10. Final simplification38.8%

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

Alternative 9: 6.7% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 73.1%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos M} \]
  10. Final simplification8.8%

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

Alternative 10: 6.7% accurate, 425.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (K m n M l) :precision binary64 1.0)
double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = 1.0d0
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
def code(K, m, n, M, l):
	return 1.0
function code(K, m, n, M, l)
	return 1.0
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0;
end
code[K_, m_, n_, M_, l_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 73.1%

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
  9. Taylor expanded in M around 0 8.7%

    \[\leadsto \color{blue}{1} \]
  10. Final simplification8.7%

    \[\leadsto 1 \]
  11. Add Preprocessing

Reproduce

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