Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.8% → 96.3%
Time: 15.7s
Alternatives: 13
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 13 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: 75.8% accurate, 1.0× speedup?

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

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

Alternative 1: 96.3% accurate, 0.7× speedup?

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

\\
\cos \left(\frac{\mathsf{expm1}\left(K \cdot \left(\left(m + n\right) + \left(K \cdot -0.5\right) \cdot {\left(m + n\right)}^{2}\right)\right)}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\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. expm1-log1p-u62.2%

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

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

      \[\leadsto \cos \left(\frac{e^{\mathsf{log1p}\left(\color{blue}{\left(m + n\right) \cdot K}\right)} - 1}{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-rr62.1%

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

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

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

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

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

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

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

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

Alternative 2: 96.6% accurate, 1.0× speedup?

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

\\
e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \cdot \cos M
\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 98.5%

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

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

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

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

Alternative 3: 95.2% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -6500000 \lor \neg \left(M \leq 1.08 \cdot 10^{+17}\right):\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -6.5e6 or 1.08e17 < M

    1. Initial program 83.3%

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

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

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

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

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

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

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

    if -6.5e6 < M < 1.08e17

    1. Initial program 71.9%

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

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

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

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

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

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

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

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

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

Alternative 4: 84.9% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -5200000:\\
\;\;\;\;e^{{m}^{2} \cdot -0.25}\\

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


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

    1. Initial program 76.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left(\left|n - m\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}}} \]
    9. Taylor expanded in m around inf 96.2%

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

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    11. Simplified96.2%

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

    if -5.2e6 < m

    1. Initial program 78.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left(\left|n - m\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}}} \]
    9. Taylor expanded in m around 0 67.4%

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

        \[\leadsto e^{\color{blue}{\left(\left|n - m\right| - \ell\right) - 0.25 \cdot {n}^{2}}} \]
      2. cancel-sign-sub-inv67.4%

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

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

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

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

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

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

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

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

Alternative 5: 55.0% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.4 \cdot 10^{-164} \lor \neg \left(n \leq 53\right):\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\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)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -1.4000000000000001e-164 or 53 < n

    1. Initial program 73.1%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Taylor expanded in M around 0 77.4%

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

    if -1.4000000000000001e-164 < n < 53

    1. Initial program 87.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 43.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-neg43.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -1.4 \cdot 10^{-164} \lor \neg \left(n \leq 53\right):\\ \;\;\;\;e^{-0.25 \cdot {n}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 63.9% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 8.8 \cdot 10^{-99}:\\
\;\;\;\;e^{{m}^{2} \cdot -0.25}\\

\mathbf{elif}\;n \leq 90000:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

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


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

    1. Initial program 84.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left(\left|n - m\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}}} \]
    9. Taylor expanded in m around inf 50.6%

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

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    11. Simplified50.6%

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

    if 8.80000000000000018e-99 < n < 9e4

    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 34.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-neg34.6%

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

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

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

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

    if 9e4 < n

    1. Initial program 58.1%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Taylor expanded in M around 0 98.4%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 65.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 820:\\
\;\;\;\;e^{{m}^{2} \cdot -0.25}\\

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


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

    1. Initial program 84.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{\left(\left|n - m\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}}} \]
    9. Taylor expanded in m around inf 50.0%

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

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    11. Simplified50.0%

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

    if 820 < n

    1. Initial program 58.7%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}}} \]
    7. Taylor expanded in M around 0 96.9%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 9.8% accurate, 3.5× speedup?

\[\begin{array}{l} \\ \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) \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (*
  (cos (- (/ (* K (+ m n)) 2.0) M))
  (+ 1.0 (* l (+ (* l (+ 0.5 (* l -0.16666666666666666))) -1.0)))))
double code(double K, double m, double n, double M, double l) {
	return cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = cos((((k * (m + n)) / 2.0d0) - m_1)) * (1.0d0 + (l * ((l * (0.5d0 + (l * (-0.16666666666666666d0)))) + (-1.0d0))))
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)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
}
def code(K, m, n, M, l):
	return math.cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)))
function code(K, m, n, M, l)
	return 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))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * (0.5 + (l * -0.16666666666666666))) + -1.0)));
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[(1.0 + N[(l * N[(N[(l * N[(0.5 + N[(l * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\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)
\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 29.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-neg29.7%

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

    \[\leadsto \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) \]
  8. Add Preprocessing

Alternative 9: 10.0% accurate, 3.5× speedup?

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

\\
\left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right) \cdot \cos \left(\frac{K \cdot n}{2} - M\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 29.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-neg29.7%

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

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

    \[\leadsto \cos \left(\frac{\color{blue}{K \cdot n}}{2} - M\right) \cdot e^{-\ell} \]
  7. Step-by-step derivation
    1. *-commutative31.5%

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

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

    \[\leadsto \cos \left(\frac{n \cdot K}{2} - M\right) \cdot \color{blue}{\left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + -0.16666666666666666 \cdot \ell\right) - 1\right)\right)} \]
  10. Final simplification9.2%

    \[\leadsto \left(1 + \ell \cdot \left(\ell \cdot \left(0.5 + \ell \cdot -0.16666666666666666\right) + -1\right)\right) \cdot \cos \left(\frac{K \cdot n}{2} - M\right) \]
  11. Add Preprocessing

Alternative 10: 9.2% accurate, 3.6× speedup?

\[\begin{array}{l} \\ \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) \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (* (cos (- (/ (* K (+ m n)) 2.0) M)) (+ 1.0 (* l (+ (* l 0.5) -1.0)))))
double code(double K, double m, double n, double M, double l) {
	return cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * 0.5) + -1.0)));
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = cos((((k * (m + n)) / 2.0d0) - m_1)) * (1.0d0 + (l * ((l * 0.5d0) + (-1.0d0))))
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)) * (1.0 + (l * ((l * 0.5) + -1.0)));
}
def code(K, m, n, M, l):
	return math.cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * 0.5) + -1.0)))
function code(K, m, n, M, l)
	return Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * Float64(1.0 + Float64(l * Float64(Float64(l * 0.5) + -1.0))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos((((K * (m + n)) / 2.0) - M)) * (1.0 + (l * ((l * 0.5) + -1.0)));
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[(1.0 + N[(l * N[(N[(l * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\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)
\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 29.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-neg29.7%

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

    \[\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)} \]
  7. Final simplification9.3%

    \[\leadsto \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) \]
  8. Add Preprocessing

Alternative 11: 9.4% accurate, 3.6× speedup?

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

\\
\cos \left(\frac{K \cdot n}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.5 + -1\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 29.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-neg29.7%

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

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

    \[\leadsto \cos \left(\frac{\color{blue}{K \cdot n}}{2} - M\right) \cdot e^{-\ell} \]
  7. Step-by-step derivation
    1. *-commutative31.5%

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

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

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

    \[\leadsto \cos \left(\frac{K \cdot n}{2} - M\right) \cdot \left(1 + \ell \cdot \left(\ell \cdot 0.5 + -1\right)\right) \]
  11. Add Preprocessing

Alternative 12: 6.9% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 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 29.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-neg29.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified6.3%

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

Alternative 13: 6.9% accurate, 425.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 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 29.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-neg29.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified6.3%

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

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

Reproduce

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