Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 77.3% → 97.1%
Time: 16.8s
Alternatives: 11
Speedup: 1.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 77.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: 97.1% accurate, 1.0× speedup?

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

\\
e^{\left|n - m\right| - \left(\ell + {\left(0.5 \cdot \left(n + m\right) - M\right)}^{2}\right)} \cdot \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 K around 0 95.7%

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

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

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

Alternative 2: 92.0% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := {\left(0.5 \cdot \left(n + m\right) - M\right)}^{2}\\
\mathbf{if}\;K \leq -8 \cdot 10^{+149} \lor \neg \left(K \leq 1.2 \cdot 10^{+69}\right):\\
\;\;\;\;\cos M \cdot e^{\left(n - m\right) - t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < -8.00000000000000039e149 or 1.2000000000000001e69 < K

    1. Initial program 33.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 89.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. Simplified89.5%

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

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

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

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

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

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

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

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

    if -8.00000000000000039e149 < K < 1.2000000000000001e69

    1. Initial program 97.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. Step-by-step derivation
      1. sub-neg97.8%

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

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

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{-\left({\color{blue}{\left(\mathsf{fma}\left(m + n, \frac{1}{2}, -M\right)\right)}}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      5. metadata-eval97.8%

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

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{-\left({\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2} + \left(\ell - \color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right)\right)} \]
      8. add-sqr-sqrt97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{-\left({\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2} + \left(\ell - \color{blue}{\left(m - n\right)}\right)\right)} \]
    4. Applied egg-rr97.8%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{-\color{blue}{\left(\left(\ell - \left(m - n\right)\right) + {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}\right)}} \]
      2. distribute-neg-in97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{\left(-\left(\ell - \left(m - n\right)\right)\right) + \left(-{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}\right)}} \]
      3. sub-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{\left(-\left(\ell - \left(m - n\right)\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}} \]
      4. sub-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-\color{blue}{\left(\ell + \left(-\left(m - n\right)\right)\right)}\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      5. distribute-neg-in97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{\left(\left(-\ell\right) + \left(-\left(-\left(m - n\right)\right)\right)\right)} - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      6. sub-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \left(-\left(-\color{blue}{\left(m + \left(-n\right)\right)}\right)\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      7. mul-1-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \left(-\left(-\left(m + \color{blue}{-1 \cdot n}\right)\right)\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      8. distribute-neg-in97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \left(-\color{blue}{\left(\left(-m\right) + \left(--1 \cdot n\right)\right)}\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      9. mul-1-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \left(-\left(\color{blue}{-1 \cdot m} + \left(--1 \cdot n\right)\right)\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      10. mul-1-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \left(-\left(-1 \cdot m + \left(-\color{blue}{\left(-n\right)}\right)\right)\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      11. remove-double-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \left(-\left(-1 \cdot m + \color{blue}{n}\right)\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      12. distribute-neg-in97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \color{blue}{\left(\left(--1 \cdot m\right) + \left(-n\right)\right)}\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      13. mul-1-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \left(\left(-\color{blue}{\left(-m\right)}\right) + \left(-n\right)\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      14. remove-double-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \left(\color{blue}{m} + \left(-n\right)\right)\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      15. sub-neg97.8%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left(-\ell\right) + \color{blue}{\left(m - n\right)}\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}} \]
      16. fmm-undef97.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq -8 \cdot 10^{+149} \lor \neg \left(K \leq 1.2 \cdot 10^{+69}\right):\\ \;\;\;\;\cos M \cdot e^{\left(n - m\right) - {\left(0.5 \cdot \left(n + m\right) - M\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(0.5 \cdot \left(n + m\right) - M\right)}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 92.1% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 77.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 94.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. Simplified94.0%

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

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

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

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

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

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

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

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

    if 730 < l

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

Alternative 4: 84.3% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 77.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 94.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. Simplified94.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\left(n - m\right) - 0.25 \cdot \color{blue}{\left(\left(m + n\right) \cdot \left(m + n\right)\right)}} \cdot \cos M \]
    10. Applied egg-rr76.0%

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

    if 730 < l

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

Alternative 5: 67.2% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 77.3%

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

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

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

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

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

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

    if 720 < l

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

Alternative 6: 49.6% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 77.3%

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*32.4%

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

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

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

    if 720 < l

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

Alternative 7: 49.6% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 77.3%

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*32.4%

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

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

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

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

    if 720 < l

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

Alternative 8: 29.0% accurate, 3.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -3 \cdot 10^{+57} \lor \neg \left(m \leq 1.15 \cdot 10^{-256}\right):\\
\;\;\;\;e^{-0.5 \cdot \left(n \cdot m\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -3e57 or 1.15e-256 < m

    1. Initial program 76.0%

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{{n}^{2} \cdot \left(\frac{M}{n} - \left(0.25 + 0.5 \cdot \frac{m}{n}\right)\right)} \]
    6. Simplified45.7%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*36.4%

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

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

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

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

    if -3e57 < m < 1.15e-256

    1. Initial program 83.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 l around inf 44.0%

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

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

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + -0.16666666666666666 \cdot \ell\right) - 1\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification29.5%

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

Alternative 9: 29.0% accurate, 3.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -6.2 \cdot 10^{+41} \lor \neg \left(m \leq 2.4 \cdot 10^{-256}\right):\\
\;\;\;\;e^{-0.5 \cdot \left(n \cdot m\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos \left(\frac{\left(n + m\right) \cdot K}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.5 + -1\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -6.2e41 or 2.3999999999999999e-256 < m

    1. Initial program 76.2%

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
    8. Step-by-step derivation
      1. associate-*r*36.2%

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

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

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

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

    if -6.2e41 < m < 2.3999999999999999e-256

    1. Initial program 83.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 l around inf 44.5%

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

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

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

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

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

Alternative 10: 31.1% accurate, 4.0× speedup?

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

\\
e^{-0.5 \cdot \left(n \cdot m\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 n around inf 36.3%

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

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-0.5 \cdot \left(m \cdot n\right)}} \]
  8. Step-by-step derivation
    1. associate-*r*31.9%

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

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

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

    \[\leadsto \color{blue}{e^{-0.5 \cdot \left(m \cdot n\right)}} \]
  11. Final simplification31.9%

    \[\leadsto e^{-0.5 \cdot \left(n \cdot m\right)} \]
  12. Add Preprocessing

Alternative 11: 7.4% 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 l around inf 33.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-neg33.7%

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

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

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  8. Step-by-step derivation
    1. cos-neg5.4%

      \[\leadsto \color{blue}{\cos M} \]
  9. Simplified5.4%

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

Reproduce

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