Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.0% → 96.6%
Time: 23.9s
Alternatives: 9
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 9 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.0% 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.6% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 93.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. Step-by-step derivation
      1. add-cube-cbrt94.7%

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

        \[\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)} \]
    3. Applied egg-rr94.8%

      \[\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 +inf.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)) (-.f64 l (fabs.f64 (-.f64 m n))))))

    1. Initial program 0.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. Taylor expanded in M around 0 0.0%

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

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

        \[\leadsto \cos \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m + n\right)\right) \cdot e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)} \]
      3. *-commutative0.0%

        \[\leadsto \cos \color{blue}{\left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right)} \cdot e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)} \]
      4. *-commutative0.0%

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

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

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

    \[\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 \infty:\\ \;\;\;\;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^{\left|m - n\right| - \left(\ell + {\left(m + n\right)}^{2} \cdot 0.25\right)}\\ \end{array} \]

Alternative 2: 96.7% accurate, 1.0× speedup?

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

\\
\cos M \cdot e^{\left(\left|m - n\right| - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right) - \ell}
\end{array}
Derivation
  1. Initial program 72.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. Taylor expanded in K around 0 94.0%

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

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

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

Alternative 3: 94.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;M \leq -2 \cdot 10^{+103} \lor \neg \left(M \leq 6.5 \cdot 10^{+31}\right):\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right) - \ell}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + {\left(m + n\right)}^{2} \cdot 0.25\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (or (<= M -2e+103) (not (<= M 6.5e+31)))
   (* (cos M) (exp (- (* M (- M)) l)))
   (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 <= -2e+103) || !(M <= 6.5e+31)) {
		tmp = cos(M) * exp(((M * -M) - l));
	} 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 <= (-2d+103)) .or. (.not. (m_1 <= 6.5d+31))) then
        tmp = cos(m_1) * exp(((m_1 * -m_1) - l))
    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 <= -2e+103) || !(M <= 6.5e+31)) {
		tmp = Math.cos(M) * Math.exp(((M * -M) - l));
	} 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 <= -2e+103) or not (M <= 6.5e+31):
		tmp = math.cos(M) * math.exp(((M * -M) - l))
	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 <= -2e+103) || !(M <= 6.5e+31))
		tmp = Float64(cos(M) * exp(Float64(Float64(M * Float64(-M)) - l)));
	else
		tmp = exp(Float64(abs(Float64(m - n)) - Float64(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 <= -2e+103) || ~((M <= 6.5e+31)))
		tmp = cos(M) * exp(((M * -M) - l));
	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, -2e+103], N[Not[LessEqual[M, 6.5e+31]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(M * (-M)), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(l + N[(N[Power[N[(m + n), $MachinePrecision], 2.0], $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;M \leq -2 \cdot 10^{+103} \lor \neg \left(M \leq 6.5 \cdot 10^{+31}\right):\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right) - \ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -2e103 or 6.5000000000000004e31 < M

    1. Initial program 73.5%

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(-{M}^{2}\right)} - \ell} \]
      2. unpow299.0%

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{M \cdot M}\right) - \ell} \]
      3. distribute-rgt-neg-in99.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)} - \ell} \]
    6. Simplified99.0%

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

    if -2e103 < M < 6.5000000000000004e31

    1. Initial program 72.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. Taylor expanded in M around 0 71.9%

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

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

        \[\leadsto \cos \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m + n\right)\right) \cdot e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)} \]
      3. *-commutative71.9%

        \[\leadsto \cos \color{blue}{\left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right)} \cdot e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)} \]
      4. *-commutative71.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -2 \cdot 10^{+103} \lor \neg \left(M \leq 6.5 \cdot 10^{+31}\right):\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right) - \ell}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + {\left(m + n\right)}^{2} \cdot 0.25\right)}\\ \end{array} \]

Alternative 4: 77.5% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;n \leq 6.8 \cdot 10^{-10}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right) - \ell}\\

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


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

    1. Initial program 65.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. Taylor expanded in K around 0 91.1%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}} - \ell} \]
    5. Step-by-step derivation
      1. *-commutative70.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25} - \ell} \]
      2. unpow270.0%

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

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

    if -8.00000000000000031e-153 < n < 6.8000000000000003e-10

    1. Initial program 84.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. Taylor expanded in K around 0 93.4%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(-{M}^{2}\right)} - \ell} \]
      2. unpow282.5%

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{M \cdot M}\right) - \ell} \]
      3. distribute-rgt-neg-in82.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)} - \ell} \]
    6. Simplified82.5%

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

    if 6.8000000000000003e-10 < n

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {n}^{2}} - \ell} \]
    5. Step-by-step derivation
      1. *-commutative89.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25} - \ell} \]
      2. unpow289.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25 - \ell} \]
    6. Simplified89.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -8 \cdot 10^{-153}:\\ \;\;\;\;\cos M \cdot e^{\left(m \cdot m\right) \cdot -0.25 - \ell}\\ \mathbf{elif}\;n \leq 6.8 \cdot 10^{-10}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right) - \ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(n \cdot n\right) - \ell}\\ \end{array} \]

Alternative 5: 75.5% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -8.5 \cdot 10^{-153} \lor \neg \left(n \leq 32000\right):\\
\;\;\;\;e^{n \cdot \left(m \cdot -0.5 + n \cdot -0.25\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -8.4999999999999996e-153 or 32000 < n

    1. Initial program 65.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. Taylor expanded in M around 0 61.7%

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

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

        \[\leadsto \cos \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m + n\right)\right) \cdot e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)} \]
      3. *-commutative61.7%

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

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

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

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

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{{n}^{2} \cdot -0.25} + -0.5 \cdot \left(m \cdot n\right)} \]
      3. fma-def42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{\mathsf{fma}\left({n}^{2}, -0.25, -0.5 \cdot \left(m \cdot n\right)\right)}} \]
      4. unpow242.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(\color{blue}{n \cdot n}, -0.25, -0.5 \cdot \left(m \cdot n\right)\right)} \]
      5. associate-*r*42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \color{blue}{\left(-0.5 \cdot m\right) \cdot n}\right)} \]
      6. metadata-eval42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n\right)} \]
      7. *-commutative42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \color{blue}{n \cdot \left(\left(-0.5\right) \cdot m\right)}\right)} \]
      8. metadata-eval42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(\color{blue}{-0.5} \cdot m\right)\right)} \]
      9. *-commutative42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \color{blue}{\left(m \cdot -0.5\right)}\right)} \]
    7. Simplified42.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)}} \]
    8. Taylor expanded in K around 0 58.4%

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

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

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

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

        \[\leadsto e^{n \cdot \left(-0.5 \cdot m\right) + \color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      5. associate-*l*58.4%

        \[\leadsto e^{n \cdot \left(-0.5 \cdot m\right) + \color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
      6. distribute-lft-out63.1%

        \[\leadsto e^{\color{blue}{n \cdot \left(-0.5 \cdot m + n \cdot -0.25\right)}} \]
    10. Simplified63.1%

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

    if -8.4999999999999996e-153 < n < 32000

    1. Initial program 83.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. Taylor expanded in K around 0 93.6%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(-{M}^{2}\right)} - \ell} \]
      2. unpow282.3%

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{M \cdot M}\right) - \ell} \]
      3. distribute-rgt-neg-in82.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)} - \ell} \]
    6. Simplified82.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -8.5 \cdot 10^{-153} \lor \neg \left(n \leq 32000\right):\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5 + n \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right) - \ell}\\ \end{array} \]

Alternative 6: 72.4% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq 4.8 \cdot 10^{-180}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right) - \ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if m < -8.6e13

    1. Initial program 70.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. Taylor expanded in K around 0 98.3%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25} - \ell} \]
      2. unpow296.6%

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

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

    if -8.6e13 < m < 4.79999999999999959e-180

    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. Taylor expanded in K around 0 87.7%

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(-\color{blue}{M \cdot M}\right) - \ell} \]
      3. distribute-rgt-neg-in75.9%

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

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

    if 4.79999999999999959e-180 < m

    1. Initial program 70.2%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{\mathsf{fma}\left({n}^{2}, -0.25, -0.5 \cdot \left(m \cdot n\right)\right)}} \]
      4. unpow226.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(\color{blue}{n \cdot n}, -0.25, -0.5 \cdot \left(m \cdot n\right)\right)} \]
      5. associate-*r*26.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \color{blue}{\left(-0.5 \cdot m\right) \cdot n}\right)} \]
      6. metadata-eval26.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n\right)} \]
      7. *-commutative26.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \color{blue}{n \cdot \left(\left(-0.5\right) \cdot m\right)}\right)} \]
      8. metadata-eval26.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(\color{blue}{-0.5} \cdot m\right)\right)} \]
      9. *-commutative26.3%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \color{blue}{\left(m \cdot -0.5\right)}\right)} \]
    7. Simplified26.3%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)}} \]
    8. Taylor expanded in K around 0 42.9%

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

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

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

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

        \[\leadsto e^{n \cdot \left(-0.5 \cdot m\right) + \color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      5. associate-*l*42.9%

        \[\leadsto e^{n \cdot \left(-0.5 \cdot m\right) + \color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
      6. distribute-lft-out45.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -86000000000000:\\ \;\;\;\;\cos M \cdot e^{\left(m \cdot m\right) \cdot -0.25 - \ell}\\ \mathbf{elif}\;m \leq 4.8 \cdot 10^{-180}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right) - \ell}\\ \mathbf{else}:\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5 + n \cdot -0.25\right)}\\ \end{array} \]

Alternative 7: 62.3% accurate, 3.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -3.25 \cdot 10^{-167} \lor \neg \left(n \leq 54\right):\\
\;\;\;\;e^{n \cdot \left(m \cdot -0.5 + n \cdot -0.25\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -3.24999999999999987e-167 or 54 < n

    1. Initial program 65.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. Taylor expanded in M around 0 61.7%

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

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

        \[\leadsto \cos \left(\color{blue}{\left(K \cdot 0.5\right)} \cdot \left(m + n\right)\right) \cdot e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)} \]
      3. *-commutative61.7%

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

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

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

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

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

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{{n}^{2} \cdot -0.25} + -0.5 \cdot \left(m \cdot n\right)} \]
      3. fma-def42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{\mathsf{fma}\left({n}^{2}, -0.25, -0.5 \cdot \left(m \cdot n\right)\right)}} \]
      4. unpow242.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(\color{blue}{n \cdot n}, -0.25, -0.5 \cdot \left(m \cdot n\right)\right)} \]
      5. associate-*r*42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \color{blue}{\left(-0.5 \cdot m\right) \cdot n}\right)} \]
      6. metadata-eval42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n\right)} \]
      7. *-commutative42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \color{blue}{n \cdot \left(\left(-0.5\right) \cdot m\right)}\right)} \]
      8. metadata-eval42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(\color{blue}{-0.5} \cdot m\right)\right)} \]
      9. *-commutative42.1%

        \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \color{blue}{\left(m \cdot -0.5\right)}\right)} \]
    7. Simplified42.1%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)}} \]
    8. Taylor expanded in K around 0 58.4%

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

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

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

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

        \[\leadsto e^{n \cdot \left(-0.5 \cdot m\right) + \color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      5. associate-*l*58.4%

        \[\leadsto e^{n \cdot \left(-0.5 \cdot m\right) + \color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
      6. distribute-lft-out63.1%

        \[\leadsto e^{\color{blue}{n \cdot \left(-0.5 \cdot m + n \cdot -0.25\right)}} \]
    10. Simplified63.1%

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

    if -3.24999999999999987e-167 < n < 54

    1. Initial program 83.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. Taylor expanded in M around 0 75.4%

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

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

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

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

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

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

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

      \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    7. Step-by-step derivation
      1. neg-mul-145.4%

        \[\leadsto 1 \cdot e^{\color{blue}{-\ell}} \]
    8. Simplified45.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -3.25 \cdot 10^{-167} \lor \neg \left(n \leq 54\right):\\ \;\;\;\;e^{n \cdot \left(m \cdot -0.5 + n \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 8: 35.8% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 72.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. Taylor expanded in M around 0 67.2%

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

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

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

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

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

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

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

    \[\leadsto 1 \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  7. Step-by-step derivation
    1. neg-mul-137.8%

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

    \[\leadsto 1 \cdot e^{\color{blue}{-\ell}} \]
  9. Final simplification37.8%

    \[\leadsto e^{-\ell} \]

Alternative 9: 6.4% accurate, 38.6× speedup?

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

\\
1 + -0.125 \cdot \left(\left(m \cdot m\right) \cdot \left(K \cdot K\right)\right)
\end{array}
Derivation
  1. Initial program 72.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. Taylor expanded in M around 0 67.2%

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

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

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

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

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

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

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

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

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{{n}^{2} \cdot -0.25} + -0.5 \cdot \left(m \cdot n\right)} \]
    3. fma-def29.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{\mathsf{fma}\left({n}^{2}, -0.25, -0.5 \cdot \left(m \cdot n\right)\right)}} \]
    4. unpow229.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(\color{blue}{n \cdot n}, -0.25, -0.5 \cdot \left(m \cdot n\right)\right)} \]
    5. associate-*r*29.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \color{blue}{\left(-0.5 \cdot m\right) \cdot n}\right)} \]
    6. metadata-eval29.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \left(\color{blue}{\left(-0.5\right)} \cdot m\right) \cdot n\right)} \]
    7. *-commutative29.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, \color{blue}{n \cdot \left(\left(-0.5\right) \cdot m\right)}\right)} \]
    8. metadata-eval29.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(\color{blue}{-0.5} \cdot m\right)\right)} \]
    9. *-commutative29.9%

      \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \color{blue}{\left(m \cdot -0.5\right)}\right)} \]
  7. Simplified29.9%

    \[\leadsto \cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right)\right) \cdot e^{\color{blue}{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)}} \]
  8. Taylor expanded in K around 0 13.6%

    \[\leadsto \color{blue}{\left(1 + -0.125 \cdot \left({K}^{2} \cdot {\left(m + n\right)}^{2}\right)\right)} \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)} \]
  9. Step-by-step derivation
    1. *-commutative13.6%

      \[\leadsto \left(1 + -0.125 \cdot \color{blue}{\left({\left(m + n\right)}^{2} \cdot {K}^{2}\right)}\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)} \]
    2. +-commutative13.6%

      \[\leadsto \left(1 + -0.125 \cdot \left({\color{blue}{\left(n + m\right)}}^{2} \cdot {K}^{2}\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)} \]
    3. unpow213.6%

      \[\leadsto \left(1 + -0.125 \cdot \left({\left(n + m\right)}^{2} \cdot \color{blue}{\left(K \cdot K\right)}\right)\right) \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)} \]
  10. Simplified13.6%

    \[\leadsto \color{blue}{\left(1 + -0.125 \cdot \left({\left(n + m\right)}^{2} \cdot \left(K \cdot K\right)\right)\right)} \cdot e^{\mathsf{fma}\left(n \cdot n, -0.25, n \cdot \left(m \cdot -0.5\right)\right)} \]
  11. Taylor expanded in n around 0 5.8%

    \[\leadsto \color{blue}{1 + -0.125 \cdot \left({K}^{2} \cdot {m}^{2}\right)} \]
  12. Step-by-step derivation
    1. unpow25.8%

      \[\leadsto 1 + -0.125 \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot {m}^{2}\right) \]
    2. unpow25.8%

      \[\leadsto 1 + -0.125 \cdot \left(\left(K \cdot K\right) \cdot \color{blue}{\left(m \cdot m\right)}\right) \]
  13. Simplified5.8%

    \[\leadsto \color{blue}{1 + -0.125 \cdot \left(\left(K \cdot K\right) \cdot \left(m \cdot m\right)\right)} \]
  14. Final simplification5.8%

    \[\leadsto 1 + -0.125 \cdot \left(\left(m \cdot m\right) \cdot \left(K \cdot K\right)\right) \]

Reproduce

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