Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.4% → 96.8%
Time: 15.6s
Alternatives: 11
Speedup: 3.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 76.4% accurate, 1.0× speedup?

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

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

Alternative 1: 96.8% accurate, 0.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;e^{\left(m - n\right) - \left(\ell + {\left(t\_1 - M\right)}^{2}\right)}\\


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

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

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

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

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

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

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

      \[\leadsto \cos \left(\color{blue}{{\left(\sqrt[3]{K \cdot \left(\left(m + n\right) \cdot 0.5\right)}\right)}^{3}} - 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)) #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 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. Add Preprocessing
    3. Taylor expanded in K around 0 98.0%

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

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

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{\left|m - n\right|} - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
      5. rem-square-sqrt50.0%

        \[\leadsto 1 \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
      6. fabs-sqr50.0%

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

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

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

    \[\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({\left(\sqrt[3]{K \cdot \left(\left(m + n\right) \cdot 0.5\right)}\right)}^{3} - M\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\left(m - n\right) - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.7% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 95.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. Step-by-step derivation
      1. clear-num95.9%

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

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

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

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

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

      \[\leadsto \cos \left(\color{blue}{\frac{1}{\frac{\frac{2}{K}}{m + n}}} - 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)) #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 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. Add Preprocessing
    3. Taylor expanded in K around 0 98.0%

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

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

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{\left|m - n\right|} - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
      5. rem-square-sqrt50.0%

        \[\leadsto 1 \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
      6. fabs-sqr50.0%

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

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

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

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

Alternative 3: 96.8% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \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}}\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 95.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

    if +inf.0 < (*.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 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. Add Preprocessing
    3. Taylor expanded in K around 0 98.0%

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

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

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

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

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

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

        \[\leadsto 1 \cdot e^{\color{blue}{\left|m - n\right|} - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
      5. rem-square-sqrt50.0%

        \[\leadsto 1 \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
      6. fabs-sqr50.0%

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

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

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

    \[\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:\\ \;\;\;\;\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}}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(m - n\right) - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 96.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ 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
 (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 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 = 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.exp((Math.abs((m - n)) - (l + Math.pow((((m + n) * 0.5) - M), 2.0))));
}
def code(K, m, n, M, l):
	return math.exp((math.fabs((m - n)) - (l + math.pow((((m + n) * 0.5) - M), 2.0))))
function code(K, m, n, M, l)
	return 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 = exp((abs((m - n)) - (l + ((((m + n) * 0.5) - M) ^ 2.0))));
end
code[K_, m_, n_, M_, l_] := 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]
\begin{array}{l}

\\
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.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 94.5%

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

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

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

Alternative 5: 96.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ 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
 (exp (- (- m n) (+ l (pow (- (* (+ m n) 0.5) M) 2.0)))))
double code(double K, double m, double n, double M, double l) {
	return exp(((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 = exp(((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.exp(((m - n) - (l + Math.pow((((m + n) * 0.5) - M), 2.0))));
}
def code(K, m, n, M, l):
	return math.exp(((m - n) - (l + math.pow((((m + n) * 0.5) - M), 2.0))))
function code(K, m, n, M, l)
	return exp(Float64(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 = exp(((m - n) - (l + ((((m + n) * 0.5) - M) ^ 2.0))));
end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[(m - n), $MachinePrecision] - N[(l + N[Power[N[(N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\left(m - n\right) - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}
\end{array}
Derivation
  1. Initial program 77.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 94.5%

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

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

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

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

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

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

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

      \[\leadsto 1 \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
    6. fabs-sqr47.5%

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

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

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

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

Alternative 6: 74.8% accurate, 2.0× speedup?

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

\\
e^{\left(m - n\right) - \left({M}^{2} + \ell\right)}
\end{array}
Derivation
  1. Initial program 77.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 94.5%

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

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

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

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

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

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

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

      \[\leadsto 1 \cdot e^{\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
    6. fabs-sqr47.5%

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

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

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

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

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

Alternative 7: 86.4% accurate, 3.7× 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 (+ (- (- m n) l) (* -0.25 (* (+ m n) (+ m n))))))
double code(double K, double m, double n, double M, double l) {
	return exp((((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((((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((((m - n) - l) + (-0.25 * ((m + n) * (m + n)))));
}
def code(K, m, n, M, l):
	return math.exp((((m - n) - l) + (-0.25 * ((m + n) * (m + n)))))
function code(K, m, n, M, l)
	return exp(Float64(Float64(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((((m - n) - l) + (-0.25 * ((m + n) * (m + n)))));
end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[(N[(m - n), $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.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 94.5%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 1 \cdot 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. Applied egg-rr85.9%

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

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

Alternative 8: 6.6% accurate, 4.0× speedup?

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

\\
\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)
\end{array}
Derivation
  1. Initial program 77.2%

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

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

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

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

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

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

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
  9. Simplified7.6%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(n \cdot K\right) - M\right)} \]
  10. Final simplification7.6%

    \[\leadsto \cos \left(0.5 \cdot \left(K \cdot n\right) - M\right) \]
  11. Add Preprocessing

Alternative 9: 6.6% accurate, 4.0× speedup?

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

\\
\cos \left(0.5 \cdot \left(K \cdot n\right)\right)
\end{array}
Derivation
  1. Initial program 77.2%

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

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

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

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

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

      \[\leadsto \cos \left(0.5 \cdot \left(K \cdot \color{blue}{\left(n + m\right)}\right) - M\right) \]
    2. add-cbrt-cube5.9%

      \[\leadsto \cos \left(0.5 \cdot \left(K \cdot \color{blue}{\sqrt[3]{\left(\left(n + m\right) \cdot \left(n + m\right)\right) \cdot \left(n + m\right)}}\right) - M\right) \]
    3. pow1/34.3%

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

      \[\leadsto \cos \left(0.5 \cdot \left(K \cdot {\left(\left(\color{blue}{\left(m + n\right)} \cdot \left(n + m\right)\right) \cdot \left(n + m\right)\right)}^{0.3333333333333333}\right) - M\right) \]
    5. +-commutative4.3%

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

      \[\leadsto \cos \left(0.5 \cdot \left(K \cdot {\left(\left(\left(m + n\right) \cdot \left(m + n\right)\right) \cdot \color{blue}{\left(m + n\right)}\right)}^{0.3333333333333333}\right) - M\right) \]
    7. pow34.3%

      \[\leadsto \cos \left(0.5 \cdot \left(K \cdot {\color{blue}{\left({\left(m + n\right)}^{3}\right)}}^{0.3333333333333333}\right) - M\right) \]
  8. Applied egg-rr4.3%

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

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

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)}\right) \]
  11. Simplified7.6%

    \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right)\right)} \]
  12. Final simplification7.6%

    \[\leadsto \cos \left(0.5 \cdot \left(K \cdot n\right)\right) \]
  13. Add Preprocessing

Alternative 10: 6.9% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 77.2%

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

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

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

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

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

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

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

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

Alternative 11: 6.9% accurate, 425.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 77.2%

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

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

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

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

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

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

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

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

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

Reproduce

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