Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 96.7%
Time: 50.0s
Alternatives: 10
Speedup: 1.3×

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.3% accurate, 1.0× speedup?

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

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

Alternative 1: 96.7% accurate, 1.0× speedup?

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

\\
\cos \left(-M\right) \cdot e^{\left|m - n\right| - \left({\left(0.5 \cdot \left(m + n\right) - M\right)}^{2} + \ell\right)}
\end{array}
Derivation
  1. Initial program 78.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 98.1%

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

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

Alternative 2: 87.9% accurate, 1.3× speedup?

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

\\
\cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(n \cdot 0.5 - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 78.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 98.1%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
    10. rem-square-sqrt37.0%

      \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
    11. fabs-sqr37.0%

      \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
    12. rem-square-sqrt86.6%

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

    \[\leadsto \cos \left(-M\right) \cdot \color{blue}{e^{\left(\left(m - n\right) - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}}} \]
  7. Final simplification86.6%

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

Alternative 3: 76.0% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 82.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{n - m}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      9. fabs-sub74.0%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt48.5%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      11. fabs-sqr48.5%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt82.9%

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + \color{blue}{\left(-M \cdot n\right)}\right)} \]
      4. distribute-rgt-neg-in63.6%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + \color{blue}{M \cdot \left(-n\right)}\right)} \]
      5. mul-1-neg63.6%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + M \cdot \color{blue}{\left(-1 \cdot n\right)}\right)} \]
      6. distribute-lft-in67.8%

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

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

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

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

    if 1.1e19 < n

    1. Initial program 68.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{n - m}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      9. fabs-sub92.7%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt4.5%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      11. fabs-sqr4.5%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt97.1%

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

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

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

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

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

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

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

Alternative 4: 75.4% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 82.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt48.2%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      11. fabs-sqr48.2%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt83.2%

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + M \cdot \color{blue}{\left(-1 \cdot n\right)}\right)} \]
      6. distribute-lft-in67.8%

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

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

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

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

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

    if 5e9 < n

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt7.2%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      11. fabs-sqr7.2%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt95.8%

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

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

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

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

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

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

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

Alternative 5: 73.8% accurate, 2.0× speedup?

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

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


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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt41.4%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      11. fabs-sqr41.4%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt84.8%

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + \color{blue}{\left(-M \cdot n\right)}\right)} \]
      4. distribute-rgt-neg-in66.0%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + \color{blue}{M \cdot \left(-n\right)}\right)} \]
      5. mul-1-neg66.0%

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

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

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

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

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

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

    if 1.9999999999999999e196 < n

    1. Initial program 53.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{n - m}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      9. fabs-sub100.0%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt3.3%

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 75.1% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt14.3%

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt96.5%

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + \color{blue}{\left(-M \cdot n\right)}\right)} \]
      4. distribute-rgt-neg-in80.6%

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

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

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

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

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

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

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

    if -1.2e39 < m

    1. Initial program 80.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt43.3%

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt83.8%

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + \color{blue}{\left(-M \cdot n\right)}\right)} \]
      4. distribute-rgt-neg-in65.1%

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

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

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

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

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

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

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

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

Alternative 7: 76.2% accurate, 3.7× speedup?

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

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

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


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

    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 K around 0 97.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\left|m - n\right|} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      10. rem-square-sqrt36.7%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      11. fabs-sqr36.7%

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
      12. rem-square-sqrt84.2%

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

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

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

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

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

        \[\leadsto \cos \left(-M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - \left(M \cdot M + \color{blue}{\left(-M \cdot n\right)}\right)} \]
      4. distribute-rgt-neg-in66.7%

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

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

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

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

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

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

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

    if 0.0050000000000000001 < l

    1. Initial program 77.6%

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

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

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

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

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

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

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

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

        \[\leadsto e^{-\ell} \cdot \cos \left(\left(0.5 \cdot K\right) \cdot \left(n + \color{blue}{1 \cdot m}\right)\right) \]
      5. metadata-eval77.6%

        \[\leadsto e^{-\ell} \cdot \cos \left(\left(0.5 \cdot K\right) \cdot \left(n + \color{blue}{\left(--1\right)} \cdot m\right)\right) \]
      6. cancel-sign-sub-inv77.6%

        \[\leadsto e^{-\ell} \cdot \cos \left(\left(0.5 \cdot K\right) \cdot \color{blue}{\left(n - -1 \cdot m\right)}\right) \]
      7. associate-*r*77.6%

        \[\leadsto e^{-\ell} \cdot \cos \color{blue}{\left(0.5 \cdot \left(K \cdot \left(n - -1 \cdot m\right)\right)\right)} \]
      8. *-commutative77.6%

        \[\leadsto e^{-\ell} \cdot \cos \left(0.5 \cdot \color{blue}{\left(\left(n - -1 \cdot m\right) \cdot K\right)}\right) \]
      9. sub-neg77.6%

        \[\leadsto e^{-\ell} \cdot \cos \left(0.5 \cdot \left(\color{blue}{\left(n + \left(--1 \cdot m\right)\right)} \cdot K\right)\right) \]
      10. mul-1-neg77.6%

        \[\leadsto e^{-\ell} \cdot \cos \left(0.5 \cdot \left(\left(n + \left(-\color{blue}{\left(-m\right)}\right)\right) \cdot K\right)\right) \]
      11. remove-double-neg77.6%

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

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

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

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

Alternative 8: 36.2% 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 78.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 l around inf 28.7%

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

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

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

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

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

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

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

      \[\leadsto e^{-\ell} \cdot \cos \left(\left(0.5 \cdot K\right) \cdot \left(n + \color{blue}{1 \cdot m}\right)\right) \]
    5. metadata-eval28.3%

      \[\leadsto e^{-\ell} \cdot \cos \left(\left(0.5 \cdot K\right) \cdot \left(n + \color{blue}{\left(--1\right)} \cdot m\right)\right) \]
    6. cancel-sign-sub-inv28.3%

      \[\leadsto e^{-\ell} \cdot \cos \left(\left(0.5 \cdot K\right) \cdot \color{blue}{\left(n - -1 \cdot m\right)}\right) \]
    7. associate-*r*28.3%

      \[\leadsto e^{-\ell} \cdot \cos \color{blue}{\left(0.5 \cdot \left(K \cdot \left(n - -1 \cdot m\right)\right)\right)} \]
    8. *-commutative28.3%

      \[\leadsto e^{-\ell} \cdot \cos \left(0.5 \cdot \color{blue}{\left(\left(n - -1 \cdot m\right) \cdot K\right)}\right) \]
    9. sub-neg28.3%

      \[\leadsto e^{-\ell} \cdot \cos \left(0.5 \cdot \left(\color{blue}{\left(n + \left(--1 \cdot m\right)\right)} \cdot K\right)\right) \]
    10. mul-1-neg28.3%

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

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

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

    \[\leadsto \color{blue}{e^{-\ell}} \]
  10. Add Preprocessing

Alternative 9: 7.3% 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 78.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 m around inf 44.8%

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

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)} \]
  7. Step-by-step derivation
    1. *-commutative9.0%

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
  8. Simplified9.0%

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  10. Step-by-step derivation
    1. cos-neg9.2%

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified9.2%

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

Alternative 10: 7.3% 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 78.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 m around inf 44.8%

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

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)} \]
  7. Step-by-step derivation
    1. *-commutative9.0%

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
  8. Simplified9.0%

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  10. Step-by-step derivation
    1. cos-neg9.2%

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified9.2%

    \[\leadsto \color{blue}{\cos M} \]
  12. Taylor expanded in M around 0 9.2%

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

Reproduce

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