Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.1% → 96.8%
Time: 33.4s
Alternatives: 10
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 10 alternatives:

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

Initial Program: 76.1% accurate, 1.0× speedup?

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

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

Alternative 1: 96.8% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \left|m - n\right| - \ell\\
t_1 := e^{t\_0 - {\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 1:\\
\;\;\;\;t\_1 \cdot \cos \left(\frac{{\left(\sqrt[3]{t\_2}\right)}^{3}}{2} - M\right)\\

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


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

    1. Initial program 96.5%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt96.6%

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

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

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

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

    1. Initial program 18.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 96.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \leq 1:\\ \;\;\;\;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(\left|m - n\right| - \ell\right) - 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 94.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;M \leq -4.8 \cdot 10^{-57} \lor \neg \left(M \leq 1.35\right):\\
\;\;\;\;\cos \left(-M\right) \cdot e^{t\_0 - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -4.80000000000000012e-57 or 1.3500000000000001 < M

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

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

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

    if -4.80000000000000012e-57 < M < 1.3500000000000001

    1. Initial program 76.6%

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

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

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

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

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

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

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

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

Alternative 3: 96.6% accurate, 1.0× speedup?

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

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

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

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

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

Alternative 4: 88.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \left|m - n\right| - \ell\\
\mathbf{if}\;n \leq -1.8 \cdot 10^{-167} \lor \neg \left(n \leq 2.4 \cdot 10^{-25}\right):\\
\;\;\;\;e^{t\_0 - 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)}\\

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


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

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

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

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

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

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

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

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

    if -1.8e-167 < n < 2.40000000000000009e-25

    1. Initial program 85.2%

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

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

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

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

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

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

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

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

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

Alternative 5: 88.5% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \left|m - n\right| - \ell\\
\mathbf{if}\;m \leq -4.4 \cdot 10^{-24} \lor \neg \left(m \leq 8.6 \cdot 10^{-176}\right):\\
\;\;\;\;e^{t\_0 - 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -4.40000000000000003e-24 or 8.60000000000000025e-176 < m

    1. Initial program 73.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 95.8%

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

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

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

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

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

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

    if -4.40000000000000003e-24 < m < 8.60000000000000025e-176

    1. Initial program 85.5%

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

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

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

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

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

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

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

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

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

Alternative 6: 85.7% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;n \leq 2 \cdot 10^{-209} \lor \neg \left(n \leq 8.4 \cdot 10^{-26}\right):\\
\;\;\;\;e^{\left(t\_0 - \ell\right) - 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 2.0000000000000001e-209 or 8.40000000000000032e-26 < n

    1. Initial program 76.2%

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

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

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

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

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

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

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

    if 2.0000000000000001e-209 < n < 8.40000000000000032e-26

    1. Initial program 86.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right) - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(-1 \cdot M\right) \cdot \left(n - M\right)}} \]
      4. neg-mul-172.2%

        \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right) - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(-M\right)} \cdot \left(n - M\right)} \]
      5. cancel-sign-sub72.2%

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

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

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

Alternative 7: 43.5% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -5.5 \cdot 10^{+66}:\\
\;\;\;\;e^{\left(m + 0.25 \cdot \left(n \cdot \left(n + m \cdot 2\right)\right)\right) - \left(n + \ell\right)}\\

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


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

    1. Initial program 68.4%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log1p-expm1-u68.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\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)}\right)\right)} \]
      2. associate-/l*68.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.5e66 < m

    1. Initial program 79.4%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log1p-expm1-u79.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\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)}\right)\right)} \]
      2. associate-/l*79.4%

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 43.9% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 80.0%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log1p-expm1-u80.0%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\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)}\right)\right)} \]
      2. associate-/l*80.0%

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

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \color{blue}{\left(\mathsf{fma}\left(K, \frac{m + n}{2}, -M\right)\right)} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}\right)\right) \]
      4. div-inv80.0%

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

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

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

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

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

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

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

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

    if 5e10 < n

    1. Initial program 72.7%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log1p-expm1-u72.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\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)}\right)\right)} \]
      2. associate-/l*72.7%

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

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\cos \color{blue}{\left(\mathsf{fma}\left(K, \frac{m + n}{2}, -M\right)\right)} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)}\right)\right) \]
      4. div-inv72.7%

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

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

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

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

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

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

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

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

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

Alternative 9: 86.4% accurate, 2.0× speedup?

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

\\
e^{\left(\left|m - n\right| - \ell\right) - 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\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 K around 0 95.8%

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

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

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

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

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

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

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

Alternative 10: 36.0% accurate, 3.7× speedup?

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

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

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. log1p-expm1-u77.8%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\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)}\right)\right)} \]
    2. associate-/l*77.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

?
herbie shell --seed 2024131 
(FPCore (K m n M l)
  :name "Maksimov and Kolovsky, Equation (32)"
  :precision binary64
  (* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))