Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.1% → 96.8%
Time: 22.0s
Alternatives: 18
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 18 alternatives:

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

Initial Program: 76.1% accurate, 1.0× speedup?

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

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

Alternative 1: 96.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\ t_1 := K \cdot \left(m + n\right)\\ \mathbf{if}\;\cos \left(\frac{t\_1}{2} - M\right) \cdot t\_0 \leq 2:\\ \;\;\;\;t\_0 \cdot \cos \left(\frac{{\left(\sqrt[3]{t\_1}\right)}^{3}}{2} - M\right)\\ \mathbf{else}:\\ \;\;\;\;e^{m - \left(\left(n + \ell\right) + 0.25 \cdot {\left(m + n\right)}^{2}\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- (- (fabs (- m n)) l) (pow (- (/ (+ m n) 2.0) M) 2.0))))
        (t_1 (* K (+ m n))))
   (if (<= (* (cos (- (/ t_1 2.0) M)) t_0) 2.0)
     (* t_0 (cos (- (/ (pow (cbrt t_1) 3.0) 2.0) M)))
     (exp (- m (+ (+ n l) (* 0.25 (pow (+ m n) 2.0))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(((fabs((m - n)) - l) - pow((((m + n) / 2.0) - M), 2.0)));
	double t_1 = K * (m + n);
	double tmp;
	if ((cos(((t_1 / 2.0) - M)) * t_0) <= 2.0) {
		tmp = t_0 * cos(((pow(cbrt(t_1), 3.0) / 2.0) - M));
	} else {
		tmp = exp((m - ((n + l) + (0.25 * pow((m + n), 2.0)))));
	}
	return tmp;
}
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(((Math.abs((m - n)) - l) - Math.pow((((m + n) / 2.0) - M), 2.0)));
	double t_1 = K * (m + n);
	double tmp;
	if ((Math.cos(((t_1 / 2.0) - M)) * t_0) <= 2.0) {
		tmp = t_0 * Math.cos(((Math.pow(Math.cbrt(t_1), 3.0) / 2.0) - M));
	} else {
		tmp = Math.exp((m - ((n + l) + (0.25 * Math.pow((m + n), 2.0)))));
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)))
	t_1 = Float64(K * Float64(m + n))
	tmp = 0.0
	if (Float64(cos(Float64(Float64(t_1 / 2.0) - M)) * t_0) <= 2.0)
		tmp = Float64(t_0 * cos(Float64(Float64((cbrt(t_1) ^ 3.0) / 2.0) - M)));
	else
		tmp = exp(Float64(m - Float64(Float64(n + l) + Float64(0.25 * (Float64(m + n) ^ 2.0)))));
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(N[(t$95$1 / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], 2.0], N[(t$95$0 * N[Cos[N[(N[(N[Power[N[Power[t$95$1, 1/3], $MachinePrecision], 3.0], $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(m - N[(N[(n + l), $MachinePrecision] + N[(0.25 * N[Power[N[(m + n), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
t_1 := K \cdot \left(m + n\right)\\
\mathbf{if}\;\cos \left(\frac{t\_1}{2} - M\right) \cdot t\_0 \leq 2:\\
\;\;\;\;t\_0 \cdot \cos \left(\frac{{\left(\sqrt[3]{t\_1}\right)}^{3}}{2} - M\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 2

    1. Initial program 96.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. Step-by-step derivation
      1. add-cube-cbrt96.6%

        \[\leadsto \cos \left(\frac{\color{blue}{\left(\sqrt[3]{K \cdot \left(m + n\right)} \cdot \sqrt[3]{K \cdot \left(m + n\right)}\right) \cdot \sqrt[3]{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. pow397.1%

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

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

    if 2 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n))))))

    1. Initial program 16.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. Step-by-step derivation
      1. sub-neg16.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.6% accurate, 1.0× speedup?

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

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

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

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

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

Alternative 3: 96.5% accurate, 1.3× speedup?

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

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

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. sub-neg77.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-out77.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-inv77.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. metadata-eval77.8%

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

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

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

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

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

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

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

Alternative 4: 38.6% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;\ell \leq 3.9 \cdot 10^{-125}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.30000000000000015e96

    1. Initial program 79.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 32.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-neg32.6%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    5. Simplified32.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 30.3%

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

    if -2.30000000000000015e96 < l < 3.89999999999999982e-125

    1. Initial program 78.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 11.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-neg11.7%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    5. Simplified11.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 11.0%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \color{blue}{\left(-\ell\right)}\right) \]
      2. unsub-neg11.0%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\left(1 - \ell\right)} \]
    8. Simplified11.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg10.5%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*10.5%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg10.5%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified10.5%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in m around inf 18.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]

    if 3.89999999999999982e-125 < l

    1. Initial program 75.8%

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

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

      \[\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 72.0%

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

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 38.1% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;\ell \leq 5.5 \cdot 10^{-126}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.40000000000000002e147

    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 l around inf 40.1%

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

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

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

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

    if -2.40000000000000002e147 < l < 5.49999999999999987e-126

    1. Initial program 78.1%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    5. Simplified11.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 10.3%

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg9.8%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*9.8%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg9.8%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified9.8%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in m around inf 17.2%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]

    if 5.49999999999999987e-126 < l

    1. Initial program 75.8%

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

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

      \[\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 72.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.4 \cdot 10^{+147}:\\ \;\;\;\;e^{-\ell} \cdot \cos \left(\frac{K \cdot m}{2} - M\right)\\ \mathbf{elif}\;\ell \leq 5.5 \cdot 10^{-126}:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 38.3% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+146}:\\ \;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right)\\ \mathbf{elif}\;\ell \leq 6.2 \cdot 10^{-127}:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= l -1.9e+146)
   (*
    (cos (- (/ (* K (+ m n)) 2.0) M))
    (+ 1.0 (* l (+ (* l (+ 0.5 (* l -0.16666666666666666))) -1.0))))
   (if (<= l 6.2e-127)
     (* 0.5 (* K (* m (* (sin M) (- 1.0 l)))))
     (* (cos M) (exp (- l))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (l <= -1.9e+146) {
		tmp = cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
	} else if (l <= 6.2e-127) {
		tmp = 0.5 * (K * (m * (sin(M) * (1.0 - l))));
	} 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 <= (-1.9d+146)) then
        tmp = cos((((k * (m + n)) / 2.0d0) - m_1)) * (1.0d0 + (l * ((l * (0.5d0 + (l * (-0.16666666666666666d0)))) + (-1.0d0))))
    else if (l <= 6.2d-127) then
        tmp = 0.5d0 * (k * (m * (sin(m_1) * (1.0d0 - l))))
    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 <= -1.9e+146) {
		tmp = Math.cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
	} else if (l <= 6.2e-127) {
		tmp = 0.5 * (K * (m * (Math.sin(M) * (1.0 - l))));
	} else {
		tmp = Math.cos(M) * Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if l <= -1.9e+146:
		tmp = math.cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)))
	elif l <= 6.2e-127:
		tmp = 0.5 * (K * (m * (math.sin(M) * (1.0 - l))))
	else:
		tmp = math.cos(M) * math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (l <= -1.9e+146)
		tmp = Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * Float64(1.0 + Float64(l * Float64(Float64(l * Float64(0.5 + Float64(l * -0.16666666666666666))) + -1.0))));
	elseif (l <= 6.2e-127)
		tmp = Float64(0.5 * Float64(K * Float64(m * Float64(sin(M) * Float64(1.0 - l)))));
	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 <= -1.9e+146)
		tmp = cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
	elseif (l <= 6.2e-127)
		tmp = 0.5 * (K * (m * (sin(M) * (1.0 - l))));
	else
		tmp = cos(M) * exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[l, -1.9e+146], N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $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], If[LessEqual[l, 6.2e-127], N[(0.5 * N[(K * N[(m * N[(N[Sin[M], $MachinePrecision] * N[(1.0 - l), $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 -1.9 \cdot 10^{+146}:\\
\;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right)\\

\mathbf{elif}\;\ell \leq 6.2 \cdot 10^{-127}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.8999999999999999e146

    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 l around inf 40.1%

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

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

      \[\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 40.1%

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

    if -1.8999999999999999e146 < l < 6.2e-127

    1. Initial program 78.1%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    5. Simplified11.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 10.3%

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg9.8%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*9.8%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg9.8%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified9.8%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in m around inf 17.2%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]

    if 6.2e-127 < l

    1. Initial program 75.8%

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

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

      \[\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 72.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{+146}:\\ \;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right)\\ \mathbf{elif}\;\ell \leq 6.2 \cdot 10^{-127}:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 96.1% accurate, 2.0× speedup?

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

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

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. sub-neg77.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-out77.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-inv77.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. metadata-eval77.8%

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

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

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

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

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

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

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

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

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

Alternative 8: 86.3% accurate, 2.0× speedup?

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

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

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. sub-neg77.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-out77.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-inv77.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. metadata-eval77.8%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 17.3% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin M \cdot \left(1 - \ell\right)\\ \mathbf{if}\;n \leq 1.12 \cdot 10^{-169}:\\ \;\;\;\;\left(K \cdot 0.5\right) \cdot \left(n \cdot t\_0\right)\\ \mathbf{elif}\;n \leq 1.52 \cdot 10^{+32}:\\ \;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(t\_0 \cdot \left(K \cdot m\right)\right)\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (sin M) (- 1.0 l))))
   (if (<= n 1.12e-169)
     (* (* K 0.5) (* n t_0))
     (if (<= n 1.52e+32)
       (*
        (cos (- (/ (* K (+ m n)) 2.0) M))
        (+ 1.0 (* l (+ (* l (+ 0.5 (* l -0.16666666666666666))) -1.0))))
       (* 0.5 (* t_0 (* K m)))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = sin(M) * (1.0 - l);
	double tmp;
	if (n <= 1.12e-169) {
		tmp = (K * 0.5) * (n * t_0);
	} else if (n <= 1.52e+32) {
		tmp = cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
	} else {
		tmp = 0.5 * (t_0 * (K * m));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sin(m_1) * (1.0d0 - l)
    if (n <= 1.12d-169) then
        tmp = (k * 0.5d0) * (n * t_0)
    else if (n <= 1.52d+32) then
        tmp = cos((((k * (m + n)) / 2.0d0) - m_1)) * (1.0d0 + (l * ((l * (0.5d0 + (l * (-0.16666666666666666d0)))) + (-1.0d0))))
    else
        tmp = 0.5d0 * (t_0 * (k * m))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.sin(M) * (1.0 - l);
	double tmp;
	if (n <= 1.12e-169) {
		tmp = (K * 0.5) * (n * t_0);
	} else if (n <= 1.52e+32) {
		tmp = Math.cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
	} else {
		tmp = 0.5 * (t_0 * (K * m));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.sin(M) * (1.0 - l)
	tmp = 0
	if n <= 1.12e-169:
		tmp = (K * 0.5) * (n * t_0)
	elif n <= 1.52e+32:
		tmp = math.cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)))
	else:
		tmp = 0.5 * (t_0 * (K * m))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(sin(M) * Float64(1.0 - l))
	tmp = 0.0
	if (n <= 1.12e-169)
		tmp = Float64(Float64(K * 0.5) * Float64(n * t_0));
	elseif (n <= 1.52e+32)
		tmp = Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * Float64(1.0 + Float64(l * Float64(Float64(l * Float64(0.5 + Float64(l * -0.16666666666666666))) + -1.0))));
	else
		tmp = Float64(0.5 * Float64(t_0 * Float64(K * m)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = sin(M) * (1.0 - l);
	tmp = 0.0;
	if (n <= 1.12e-169)
		tmp = (K * 0.5) * (n * t_0);
	elseif (n <= 1.52e+32)
		tmp = cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
	else
		tmp = 0.5 * (t_0 * (K * m));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Sin[M], $MachinePrecision] * N[(1.0 - l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, 1.12e-169], N[(N[(K * 0.5), $MachinePrecision] * N[(n * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 1.52e+32], N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $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], N[(0.5 * N[(t$95$0 * N[(K * m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin M \cdot \left(1 - \ell\right)\\
\mathbf{if}\;n \leq 1.12 \cdot 10^{-169}:\\
\;\;\;\;\left(K \cdot 0.5\right) \cdot \left(n \cdot t\_0\right)\\

\mathbf{elif}\;n \leq 1.52 \cdot 10^{+32}:\\
\;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(t\_0 \cdot \left(K \cdot m\right)\right)\\


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

    1. Initial program 79.1%

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

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

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

      \[\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 9.0%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \color{blue}{\left(-\ell\right)}\right) \]
      2. unsub-neg9.0%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\left(1 - \ell\right)} \]
    8. Simplified9.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg8.5%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*8.5%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg8.5%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified8.5%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in n around inf 27.7%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]
    13. Step-by-step derivation
      1. associate-*r*27.7%

        \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)} \]
      2. *-commutative27.7%

        \[\leadsto \left(0.5 \cdot K\right) \cdot \left(n \cdot \color{blue}{\left(\left(1 - \ell\right) \cdot \sin M\right)}\right) \]
    14. Simplified27.7%

      \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(n \cdot \left(\left(1 - \ell\right) \cdot \sin M\right)\right)} \]

    if 1.11999999999999998e-169 < n < 1.5200000000000001e32

    1. Initial program 86.1%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    5. Simplified43.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 25.7%

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

    if 1.5200000000000001e32 < n

    1. Initial program 69.1%

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

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

      \[\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 2.1%

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg2.4%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*2.4%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg2.4%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified2.4%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in m around inf 17.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]
    13. Step-by-step derivation
      1. associate-*r*22.9%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)} \]
      2. *-commutative22.9%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(m \cdot K\right)} \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right) \]
      3. *-commutative22.9%

        \[\leadsto 0.5 \cdot \left(\left(m \cdot K\right) \cdot \color{blue}{\left(\left(1 - \ell\right) \cdot \sin M\right)}\right) \]
    14. Simplified22.9%

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(m \cdot K\right) \cdot \left(\left(1 - \ell\right) \cdot \sin M\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification26.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 1.12 \cdot 10^{-169}:\\ \;\;\;\;\left(K \cdot 0.5\right) \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\\ \mathbf{elif}\;n \leq 1.52 \cdot 10^{+32}:\\ \;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(\sin M \cdot \left(1 - \ell\right)\right) \cdot \left(K \cdot m\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 17.1% accurate, 3.3× speedup?

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

\\
\begin{array}{l}
t_0 := \sin M \cdot \left(1 - \ell\right)\\
\mathbf{if}\;n \leq 7.2 \cdot 10^{-170}:\\
\;\;\;\;\left(K \cdot 0.5\right) \cdot \left(n \cdot t\_0\right)\\

\mathbf{elif}\;n \leq 1.3 \cdot 10^{+32}:\\
\;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.5 + -1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(t\_0 \cdot \left(K \cdot m\right)\right)\\


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

    1. Initial program 79.1%

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

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

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

      \[\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 9.0%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \color{blue}{\left(-\ell\right)}\right) \]
      2. unsub-neg9.0%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\left(1 - \ell\right)} \]
    8. Simplified9.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg8.5%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*8.5%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg8.5%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified8.5%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in n around inf 27.7%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]
    13. Step-by-step derivation
      1. associate-*r*27.7%

        \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)} \]
      2. *-commutative27.7%

        \[\leadsto \left(0.5 \cdot K\right) \cdot \left(n \cdot \color{blue}{\left(\left(1 - \ell\right) \cdot \sin M\right)}\right) \]
    14. Simplified27.7%

      \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(n \cdot \left(\left(1 - \ell\right) \cdot \sin M\right)\right)} \]

    if 7.2000000000000006e-170 < n < 1.3000000000000001e32

    1. Initial program 86.1%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    5. Simplified43.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 25.7%

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

    if 1.3000000000000001e32 < n

    1. Initial program 69.1%

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

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

      \[\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 2.1%

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg2.4%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*2.4%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg2.4%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified2.4%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in m around inf 17.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]
    13. Step-by-step derivation
      1. associate-*r*22.9%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)} \]
      2. *-commutative22.9%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(m \cdot K\right)} \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right) \]
      3. *-commutative22.9%

        \[\leadsto 0.5 \cdot \left(\left(m \cdot K\right) \cdot \color{blue}{\left(\left(1 - \ell\right) \cdot \sin M\right)}\right) \]
    14. Simplified22.9%

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(m \cdot K\right) \cdot \left(\left(1 - \ell\right) \cdot \sin M\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification26.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 7.2 \cdot 10^{-170}:\\ \;\;\;\;\left(K \cdot 0.5\right) \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\\ \mathbf{elif}\;n \leq 1.3 \cdot 10^{+32}:\\ \;\;\;\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.5 + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(\sin M \cdot \left(1 - \ell\right)\right) \cdot \left(K \cdot m\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 15.0% accurate, 3.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 4.2 \cdot 10^{-170} \lor \neg \left(n \leq 8.6 \cdot 10^{-49}\right):\\ \;\;\;\;0.5 \cdot \left(\left(\sin M \cdot \left(1 - \ell\right)\right) \cdot \left(K \cdot m\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right)\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (or (<= n 4.2e-170) (not (<= n 8.6e-49)))
   (* 0.5 (* (* (sin M) (- 1.0 l)) (* K m)))
   (cos (- (* (+ m n) (* K 0.5)) M))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((n <= 4.2e-170) || !(n <= 8.6e-49)) {
		tmp = 0.5 * ((sin(M) * (1.0 - l)) * (K * m));
	} else {
		tmp = cos((((m + n) * (K * 0.5)) - 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 ((n <= 4.2d-170) .or. (.not. (n <= 8.6d-49))) then
        tmp = 0.5d0 * ((sin(m_1) * (1.0d0 - l)) * (k * m))
    else
        tmp = cos((((m + n) * (k * 0.5d0)) - 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 ((n <= 4.2e-170) || !(n <= 8.6e-49)) {
		tmp = 0.5 * ((Math.sin(M) * (1.0 - l)) * (K * m));
	} else {
		tmp = Math.cos((((m + n) * (K * 0.5)) - M));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if (n <= 4.2e-170) or not (n <= 8.6e-49):
		tmp = 0.5 * ((math.sin(M) * (1.0 - l)) * (K * m))
	else:
		tmp = math.cos((((m + n) * (K * 0.5)) - M))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if ((n <= 4.2e-170) || !(n <= 8.6e-49))
		tmp = Float64(0.5 * Float64(Float64(sin(M) * Float64(1.0 - l)) * Float64(K * m)));
	else
		tmp = cos(Float64(Float64(Float64(m + n) * Float64(K * 0.5)) - M));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if ((n <= 4.2e-170) || ~((n <= 8.6e-49)))
		tmp = 0.5 * ((sin(M) * (1.0 - l)) * (K * m));
	else
		tmp = cos((((m + n) * (K * 0.5)) - M));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[n, 4.2e-170], N[Not[LessEqual[n, 8.6e-49]], $MachinePrecision]], N[(0.5 * N[(N[(N[Sin[M], $MachinePrecision] * N[(1.0 - l), $MachinePrecision]), $MachinePrecision] * N[(K * m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Cos[N[(N[(N[(m + n), $MachinePrecision] * N[(K * 0.5), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n \leq 4.2 \cdot 10^{-170} \lor \neg \left(n \leq 8.6 \cdot 10^{-49}\right):\\
\;\;\;\;0.5 \cdot \left(\left(\sin M \cdot \left(1 - \ell\right)\right) \cdot \left(K \cdot m\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 4.2000000000000001e-170 or 8.60000000000000033e-49 < n

    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 l around inf 28.9%

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

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

      \[\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 6.6%

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg6.8%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*6.8%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg6.8%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified6.8%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in m around inf 15.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]
    13. Step-by-step derivation
      1. associate-*r*17.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)} \]
      2. *-commutative17.5%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(m \cdot K\right)} \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right) \]
      3. *-commutative17.5%

        \[\leadsto 0.5 \cdot \left(\left(m \cdot K\right) \cdot \color{blue}{\left(\left(1 - \ell\right) \cdot \sin M\right)}\right) \]
    14. Simplified17.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(m \cdot K\right) \cdot \left(\left(1 - \ell\right) \cdot \sin M\right)\right)} \]

    if 4.2000000000000001e-170 < n < 8.60000000000000033e-49

    1. Initial program 82.1%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    5. Simplified42.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 21.2%

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
    10. Step-by-step derivation
      1. *-commutative21.1%

        \[\leadsto \cos \left(\color{blue}{\left(K \cdot \left(m + n\right)\right) \cdot 0.5} - M\right) \]
      2. *-commutative21.1%

        \[\leadsto \cos \left(\color{blue}{\left(\left(m + n\right) \cdot K\right)} \cdot 0.5 - M\right) \]
      3. associate-*l*21.1%

        \[\leadsto \cos \left(\color{blue}{\left(m + n\right) \cdot \left(K \cdot 0.5\right)} - M\right) \]
      4. +-commutative21.1%

        \[\leadsto \cos \left(\color{blue}{\left(n + m\right)} \cdot \left(K \cdot 0.5\right) - M\right) \]
      5. *-commutative21.1%

        \[\leadsto \cos \left(\left(n + m\right) \cdot \color{blue}{\left(0.5 \cdot K\right)} - M\right) \]
    11. Simplified21.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 4.2 \cdot 10^{-170} \lor \neg \left(n \leq 8.6 \cdot 10^{-49}\right):\\ \;\;\;\;0.5 \cdot \left(\left(\sin M \cdot \left(1 - \ell\right)\right) \cdot \left(K \cdot m\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 16.9% accurate, 3.5× speedup?

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

\\
\begin{array}{l}
t_0 := \sin M \cdot \left(1 - \ell\right)\\
\mathbf{if}\;n \leq 1.16 \cdot 10^{-169}:\\
\;\;\;\;\left(K \cdot 0.5\right) \cdot \left(n \cdot t\_0\right)\\

\mathbf{elif}\;n \leq 1.1 \cdot 10^{-46}:\\
\;\;\;\;\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(t\_0 \cdot \left(K \cdot m\right)\right)\\


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

    1. Initial program 79.1%

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

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

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

      \[\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 9.0%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \color{blue}{\left(-\ell\right)}\right) \]
      2. unsub-neg9.0%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\left(1 - \ell\right)} \]
    8. Simplified9.0%

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg8.5%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*8.5%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg8.5%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified8.5%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in n around inf 27.7%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]
    13. Step-by-step derivation
      1. associate-*r*27.7%

        \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)} \]
      2. *-commutative27.7%

        \[\leadsto \left(0.5 \cdot K\right) \cdot \left(n \cdot \color{blue}{\left(\left(1 - \ell\right) \cdot \sin M\right)}\right) \]
    14. Simplified27.7%

      \[\leadsto \color{blue}{\left(0.5 \cdot K\right) \cdot \left(n \cdot \left(\left(1 - \ell\right) \cdot \sin M\right)\right)} \]

    if 1.16e-169 < n < 1.1e-46

    1. Initial program 82.1%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-\ell}} \]
    5. Simplified42.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 21.2%

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
    10. Step-by-step derivation
      1. *-commutative21.1%

        \[\leadsto \cos \left(\color{blue}{\left(K \cdot \left(m + n\right)\right) \cdot 0.5} - M\right) \]
      2. *-commutative21.1%

        \[\leadsto \cos \left(\color{blue}{\left(\left(m + n\right) \cdot K\right)} \cdot 0.5 - M\right) \]
      3. associate-*l*21.1%

        \[\leadsto \cos \left(\color{blue}{\left(m + n\right) \cdot \left(K \cdot 0.5\right)} - M\right) \]
      4. +-commutative21.1%

        \[\leadsto \cos \left(\color{blue}{\left(n + m\right)} \cdot \left(K \cdot 0.5\right) - M\right) \]
      5. *-commutative21.1%

        \[\leadsto \cos \left(\left(n + m\right) \cdot \color{blue}{\left(0.5 \cdot K\right)} - M\right) \]
    11. Simplified21.1%

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

    if 1.1e-46 < n

    1. Initial program 74.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 31.8%

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

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

      \[\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 2.9%

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg4.2%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*4.2%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg4.2%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified4.2%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in m around inf 17.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)} \]
    13. Step-by-step derivation
      1. associate-*r*22.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)} \]
      2. *-commutative22.3%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(m \cdot K\right)} \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right) \]
      3. *-commutative22.3%

        \[\leadsto 0.5 \cdot \left(\left(m \cdot K\right) \cdot \color{blue}{\left(\left(1 - \ell\right) \cdot \sin M\right)}\right) \]
    14. Simplified22.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(\left(m \cdot K\right) \cdot \left(\left(1 - \ell\right) \cdot \sin M\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 1.16 \cdot 10^{-169}:\\ \;\;\;\;\left(K \cdot 0.5\right) \cdot \left(n \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\\ \mathbf{elif}\;n \leq 1.1 \cdot 10^{-46}:\\ \;\;\;\;\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(\sin M \cdot \left(1 - \ell\right)\right) \cdot \left(K \cdot m\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 10.5% accurate, 3.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 3.4 \cdot 10^{-48}:\\
\;\;\;\;\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(m \cdot \left(\sin M \cdot \left(1 - \ell\right)\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 3.40000000000000028e-48

    1. Initial program 79.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 29.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-neg29.6%

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

      \[\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 11.0%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \left(1 + \color{blue}{\left(-\ell\right)}\right) \]
      2. unsub-neg11.0%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\left(1 - \ell\right)} \]
    8. Simplified11.0%

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
    10. Step-by-step derivation
      1. *-commutative11.1%

        \[\leadsto \cos \left(\color{blue}{\left(K \cdot \left(m + n\right)\right) \cdot 0.5} - M\right) \]
      2. *-commutative11.1%

        \[\leadsto \cos \left(\color{blue}{\left(\left(m + n\right) \cdot K\right)} \cdot 0.5 - M\right) \]
      3. associate-*l*11.1%

        \[\leadsto \cos \left(\color{blue}{\left(m + n\right) \cdot \left(K \cdot 0.5\right)} - M\right) \]
      4. +-commutative11.1%

        \[\leadsto \cos \left(\color{blue}{\left(n + m\right)} \cdot \left(K \cdot 0.5\right) - M\right) \]
      5. *-commutative11.1%

        \[\leadsto \cos \left(\left(n + m\right) \cdot \color{blue}{\left(0.5 \cdot K\right)} - M\right) \]
    11. Simplified11.1%

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

    if 3.40000000000000028e-48 < n

    1. Initial program 74.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 31.8%

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

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

      \[\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 2.9%

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

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

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

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

      \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    10. Step-by-step derivation
      1. cos-neg4.2%

        \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
      2. associate-*r*4.2%

        \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
      3. sin-neg4.2%

        \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
    11. Simplified4.2%

      \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
    12. Taylor expanded in m around inf 17.8%

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

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

Alternative 14: 6.5% accurate, 14.7× speedup?

\[\begin{array}{l} \\ \left(1 - \ell\right) \cdot \left(1 + M \cdot \left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 + M \cdot \left(-0.08333333333333333 \cdot \left(K \cdot \left(\left(m + n\right) \cdot M\right)\right) - 0.5\right)\right)\right) \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (*
  (- 1.0 l)
  (+
   1.0
   (*
    M
    (+
     (* (* K (+ m n)) 0.5)
     (* M (- (* -0.08333333333333333 (* K (* (+ m n) M))) 0.5)))))))
double code(double K, double m, double n, double M, double l) {
	return (1.0 - l) * (1.0 + (M * (((K * (m + n)) * 0.5) + (M * ((-0.08333333333333333 * (K * ((m + n) * M))) - 0.5)))));
}
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 - l) * (1.0d0 + (m_1 * (((k * (m + n)) * 0.5d0) + (m_1 * (((-0.08333333333333333d0) * (k * ((m + n) * m_1))) - 0.5d0)))))
end function
public static double code(double K, double m, double n, double M, double l) {
	return (1.0 - l) * (1.0 + (M * (((K * (m + n)) * 0.5) + (M * ((-0.08333333333333333 * (K * ((m + n) * M))) - 0.5)))));
}
def code(K, m, n, M, l):
	return (1.0 - l) * (1.0 + (M * (((K * (m + n)) * 0.5) + (M * ((-0.08333333333333333 * (K * ((m + n) * M))) - 0.5)))))
function code(K, m, n, M, l)
	return Float64(Float64(1.0 - l) * Float64(1.0 + Float64(M * Float64(Float64(Float64(K * Float64(m + n)) * 0.5) + Float64(M * Float64(Float64(-0.08333333333333333 * Float64(K * Float64(Float64(m + n) * M))) - 0.5))))))
end
function tmp = code(K, m, n, M, l)
	tmp = (1.0 - l) * (1.0 + (M * (((K * (m + n)) * 0.5) + (M * ((-0.08333333333333333 * (K * ((m + n) * M))) - 0.5)))));
end
code[K_, m_, n_, M_, l_] := N[(N[(1.0 - l), $MachinePrecision] * N[(1.0 + N[(M * N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] + N[(M * N[(N[(-0.08333333333333333 * N[(K * N[(N[(m + n), $MachinePrecision] * M), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(1 - \ell\right) \cdot \left(1 + M \cdot \left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 + M \cdot \left(-0.08333333333333333 \cdot \left(K \cdot \left(\left(m + n\right) \cdot M\right)\right) - 0.5\right)\right)\right)
\end{array}
Derivation
  1. Initial program 77.8%

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

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

    \[\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 8.2%

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

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

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

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

    \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  10. Step-by-step derivation
    1. cos-neg8.6%

      \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
    2. associate-*r*8.6%

      \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
    3. sin-neg8.6%

      \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
  11. Simplified8.6%

    \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  12. Taylor expanded in M around 0 8.9%

    \[\leadsto \color{blue}{\left(1 + M \cdot \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) + M \cdot \left(-0.08333333333333333 \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\right) - 0.5\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  13. Final simplification8.9%

    \[\leadsto \left(1 - \ell\right) \cdot \left(1 + M \cdot \left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 + M \cdot \left(-0.08333333333333333 \cdot \left(K \cdot \left(\left(m + n\right) \cdot M\right)\right) - 0.5\right)\right)\right) \]
  14. Add Preprocessing

Alternative 15: 6.8% accurate, 22.4× speedup?

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

\\
\left(1 - \ell\right) \cdot \left(1 + M \cdot \left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 + M \cdot -0.5\right)\right)
\end{array}
Derivation
  1. Initial program 77.8%

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

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

    \[\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 8.2%

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

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

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

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

    \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  10. Step-by-step derivation
    1. cos-neg8.6%

      \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
    2. associate-*r*8.6%

      \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
    3. sin-neg8.6%

      \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
  11. Simplified8.6%

    \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  12. Taylor expanded in M around 0 8.8%

    \[\leadsto \color{blue}{\left(1 + M \cdot \left(-0.5 \cdot M + 0.5 \cdot \left(K \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  13. Final simplification8.8%

    \[\leadsto \left(1 - \ell\right) \cdot \left(1 + M \cdot \left(\left(K \cdot \left(m + n\right)\right) \cdot 0.5 + M \cdot -0.5\right)\right) \]
  14. Add Preprocessing

Alternative 16: 6.6% accurate, 28.3× speedup?

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

\\
\left(1 - \ell\right) \cdot \left(1 + 0.5 \cdot \left(\left(m + n\right) \cdot \left(K \cdot M\right)\right)\right)
\end{array}
Derivation
  1. Initial program 77.8%

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

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

    \[\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 8.2%

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

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

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

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

    \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  10. Step-by-step derivation
    1. cos-neg8.6%

      \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
    2. associate-*r*8.6%

      \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
    3. sin-neg8.6%

      \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
  11. Simplified8.6%

    \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  12. Taylor expanded in M around 0 8.4%

    \[\leadsto \color{blue}{\left(1 + 0.5 \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  13. Step-by-step derivation
    1. associate-*r*8.4%

      \[\leadsto \left(1 + 0.5 \cdot \color{blue}{\left(\left(K \cdot M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
    2. +-commutative8.4%

      \[\leadsto \left(1 + 0.5 \cdot \left(\left(K \cdot M\right) \cdot \color{blue}{\left(n + m\right)}\right)\right) \cdot \left(1 - \ell\right) \]
  14. Simplified8.4%

    \[\leadsto \color{blue}{\left(1 + 0.5 \cdot \left(\left(K \cdot M\right) \cdot \left(n + m\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  15. Final simplification8.4%

    \[\leadsto \left(1 - \ell\right) \cdot \left(1 + 0.5 \cdot \left(\left(m + n\right) \cdot \left(K \cdot M\right)\right)\right) \]
  16. Add Preprocessing

Alternative 17: 6.6% accurate, 28.3× speedup?

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

\\
\left(1 - \ell\right) \cdot \left(1 + 0.5 \cdot \left(K \cdot \left(\left(m + n\right) \cdot M\right)\right)\right)
\end{array}
Derivation
  1. Initial program 77.8%

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

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

    \[\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 8.2%

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

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

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

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

    \[\leadsto \color{blue}{\left(\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  10. Step-by-step derivation
    1. cos-neg8.6%

      \[\leadsto \left(\color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)\right) \cdot \left(1 - \ell\right) \]
    2. associate-*r*8.6%

      \[\leadsto \left(\cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)}\right) \cdot \left(1 - \ell\right) \]
    3. sin-neg8.6%

      \[\leadsto \left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot \left(m + n\right)\right)\right) \cdot \left(1 - \ell\right) \]
  11. Simplified8.6%

    \[\leadsto \color{blue}{\left(\cos M + \left(-0.5 \cdot K\right) \cdot \left(\left(-\sin M\right) \cdot \left(m + n\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  12. Taylor expanded in M around 0 8.4%

    \[\leadsto \color{blue}{\left(1 + 0.5 \cdot \left(K \cdot \left(M \cdot \left(m + n\right)\right)\right)\right)} \cdot \left(1 - \ell\right) \]
  13. Final simplification8.4%

    \[\leadsto \left(1 - \ell\right) \cdot \left(1 + 0.5 \cdot \left(K \cdot \left(\left(m + n\right) \cdot M\right)\right)\right) \]
  14. Add Preprocessing

Alternative 18: 6.8% accurate, 141.7× speedup?

\[\begin{array}{l} \\ 1 - \ell \end{array} \]
(FPCore (K m n M l) :precision binary64 (- 1.0 l))
double code(double K, double m, double n, double M, double l) {
	return 1.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 = 1.0d0 - l
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0 - l;
}
def code(K, m, n, M, l):
	return 1.0 - l
function code(K, m, n, M, l)
	return Float64(1.0 - l)
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0 - l;
end
code[K_, m_, n_, M_, l_] := N[(1.0 - l), $MachinePrecision]
\begin{array}{l}

\\
1 - \ell
\end{array}
Derivation
  1. Initial program 77.8%

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

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

    \[\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 8.2%

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(-M\right) \cdot \left(1 - \ell\right)} \]
  10. Step-by-step derivation
    1. cos-neg8.3%

      \[\leadsto \color{blue}{\cos M} \cdot \left(1 - \ell\right) \]
  11. Simplified8.3%

    \[\leadsto \color{blue}{\cos M \cdot \left(1 - \ell\right)} \]
  12. Taylor expanded in M around 0 8.3%

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

Reproduce

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