Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.7% → 96.8%
Time: 18.8s
Alternatives: 9
Speedup: 3.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 76.7% 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, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\cos M}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (/ (cos 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(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(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(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(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(M) / exp(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(M) / exp((((((m + n) / 2.0) - M) ^ 2.0) + (l - abs((m - n)))));
end
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $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}

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

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

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

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

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

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

Alternative 2: 94.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;M \leq -4 \cdot 10^{+24} \lor \neg \left(M \leq 7.8 \cdot 10^{+95}\right):\\
\;\;\;\;\frac{\cos M}{e^{M \cdot M}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -3.9999999999999999e24 or 7.7999999999999994e95 < M

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

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

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

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

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

      \[\leadsto \frac{\cos M}{e^{\color{blue}{{M}^{2}}}} \]
    7. Step-by-step derivation
      1. unpow299.0%

        \[\leadsto \frac{\cos M}{e^{\color{blue}{M \cdot M}}} \]
    8. Simplified99.0%

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

    if -3.9999999999999999e24 < M < 7.7999999999999994e95

    1. Initial program 79.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. Simplified79.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -4 \cdot 10^{+24} \lor \neg \left(M \leq 7.8 \cdot 10^{+95}\right):\\ \;\;\;\;\frac{\cos M}{e^{M \cdot M}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{\left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right) - \left|m - n\right|}}\\ \end{array} \]

Alternative 3: 73.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 2400:\\ \;\;\;\;e^{\left(\left|m - n\right| - 0.25 \cdot \left(m \cdot m\right)\right) - \ell}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 2400.0)
   (exp (- (- (fabs (- m n)) (* 0.25 (* m m))) l))
   (/ 1.0 (exp (* 0.25 (* n n))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 2400.0) {
		tmp = exp(((fabs((m - n)) - (0.25 * (m * m))) - l));
	} else {
		tmp = 1.0 / exp((0.25 * (n * 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) :: tmp
    if (n <= 2400.0d0) then
        tmp = exp(((abs((m - n)) - (0.25d0 * (m * m))) - l))
    else
        tmp = 1.0d0 / exp((0.25d0 * (n * n)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 2400.0) {
		tmp = Math.exp(((Math.abs((m - n)) - (0.25 * (m * m))) - l));
	} else {
		tmp = 1.0 / Math.exp((0.25 * (n * n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if n <= 2400.0:
		tmp = math.exp(((math.fabs((m - n)) - (0.25 * (m * m))) - l))
	else:
		tmp = 1.0 / math.exp((0.25 * (n * n)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (n <= 2400.0)
		tmp = exp(Float64(Float64(abs(Float64(m - n)) - Float64(0.25 * Float64(m * m))) - l));
	else
		tmp = Float64(1.0 / exp(Float64(0.25 * Float64(n * n))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (n <= 2400.0)
		tmp = exp(((abs((m - n)) - (0.25 * (m * m))) - l));
	else
		tmp = 1.0 / exp((0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 2400.0], N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision], N[(1.0 / N[Exp[N[(0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{0.25 \cdot \left(n \cdot n\right)}}\\


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

    1. Initial program 79.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. Simplified79.3%

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

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

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

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

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

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

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

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

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

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

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

    if 2400 < n

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

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

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

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

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

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

      \[\leadsto \frac{1}{e^{\color{blue}{0.25 \cdot {n}^{2}}}} \]
    8. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \frac{1}{e^{\color{blue}{{n}^{2} \cdot 0.25}}} \]
      2. unpow2100.0%

        \[\leadsto \frac{1}{e^{\color{blue}{\left(n \cdot n\right)} \cdot 0.25}} \]
    9. Simplified100.0%

      \[\leadsto \frac{1}{e^{\color{blue}{\left(n \cdot n\right) \cdot 0.25}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 2400:\\ \;\;\;\;e^{\left(\left|m - n\right| - 0.25 \cdot \left(m \cdot m\right)\right) - \ell}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \]

Alternative 4: 77.6% accurate, 3.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -1550:\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{\ell + \left(0.25 \cdot \left(n \cdot n\right) - n\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -1550.0)
   (/ 1.0 (exp (* 0.25 (* m m))))
   (/ 1.0 (exp (+ l (- (* 0.25 (* n n)) n))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -1550.0) {
		tmp = 1.0 / exp((0.25 * (m * m)));
	} else {
		tmp = 1.0 / exp((l + ((0.25 * (n * n)) - 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) :: tmp
    if (m <= (-1550.0d0)) then
        tmp = 1.0d0 / exp((0.25d0 * (m * m)))
    else
        tmp = 1.0d0 / exp((l + ((0.25d0 * (n * n)) - n)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -1550.0) {
		tmp = 1.0 / Math.exp((0.25 * (m * m)));
	} else {
		tmp = 1.0 / Math.exp((l + ((0.25 * (n * n)) - n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -1550.0:
		tmp = 1.0 / math.exp((0.25 * (m * m)))
	else:
		tmp = 1.0 / math.exp((l + ((0.25 * (n * n)) - n)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -1550.0)
		tmp = Float64(1.0 / exp(Float64(0.25 * Float64(m * m))));
	else
		tmp = Float64(1.0 / exp(Float64(l + Float64(Float64(0.25 * Float64(n * n)) - n))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -1550.0)
		tmp = 1.0 / exp((0.25 * (m * m)));
	else
		tmp = 1.0 / exp((l + ((0.25 * (n * n)) - n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -1550.0], N[(1.0 / N[Exp[N[(0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Exp[N[(l + N[(N[(0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision] - n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -1550:\\
\;\;\;\;\frac{1}{e^{0.25 \cdot \left(m \cdot m\right)}}\\

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


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

    1. Initial program 77.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. Simplified77.5%

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

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

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

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

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

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

        \[\leadsto \frac{1}{e^{\color{blue}{{m}^{2} \cdot 0.25}}} \]
      2. unpow296.3%

        \[\leadsto \frac{1}{e^{\color{blue}{\left(m \cdot m\right)} \cdot 0.25}} \]
    9. Simplified96.3%

      \[\leadsto \frac{1}{e^{\color{blue}{\left(m \cdot m\right) \cdot 0.25}}} \]

    if -1550 < m

    1. Initial program 78.1%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\cos \left(0.5 \cdot \left(n \cdot K\right)\right)}{e^{\left(\ell + 0.25 \cdot {n}^{2}\right) - n}}} \]
    7. Step-by-step derivation
      1. associate--l+62.8%

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

        \[\leadsto \frac{\cos \left(0.5 \cdot \left(n \cdot K\right)\right)}{e^{\ell + \left(\color{blue}{{n}^{2} \cdot 0.25} - n\right)}} \]
      3. unpow262.8%

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

      \[\leadsto \color{blue}{\frac{\cos \left(0.5 \cdot \left(n \cdot K\right)\right)}{e^{\ell + \left(\left(n \cdot n\right) \cdot 0.25 - n\right)}}} \]
    9. Taylor expanded in n around 0 77.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1550:\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{\ell + \left(0.25 \cdot \left(n \cdot n\right) - n\right)}}\\ \end{array} \]

Alternative 5: 69.4% accurate, 3.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -0.00015 \lor \neg \left(m \leq 52\right):\\
\;\;\;\;\frac{1}{e^{0.25 \cdot \left(m \cdot m\right)}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -1.49999999999999987e-4 or 52 < m

    1. Initial program 77.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. Simplified77.5%

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

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

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

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

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

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

        \[\leadsto \frac{1}{e^{\color{blue}{{m}^{2} \cdot 0.25}}} \]
      2. unpow296.2%

        \[\leadsto \frac{1}{e^{\color{blue}{\left(m \cdot m\right)} \cdot 0.25}} \]
    9. Simplified96.2%

      \[\leadsto \frac{1}{e^{\color{blue}{\left(m \cdot m\right) \cdot 0.25}}} \]

    if -1.49999999999999987e-4 < m < 52

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

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

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

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

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

      \[\leadsto \frac{\cos M}{e^{\color{blue}{\ell}}} \]
    7. Taylor expanded in M around 0 46.4%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    8. Step-by-step derivation
      1. rec-exp46.4%

        \[\leadsto \color{blue}{e^{-\ell}} \]
    9. Simplified46.4%

      \[\leadsto \color{blue}{e^{-\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -0.00015 \lor \neg \left(m \leq 52\right):\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 6: 62.4% accurate, 3.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 2.2 \cdot 10^{-231}:\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 2.2e-231)
   (/ 1.0 (exp (* 0.25 (* m m))))
   (if (<= n 54.0) (exp (- l)) (/ 1.0 (exp (* 0.25 (* n n)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 2.2e-231) {
		tmp = 1.0 / exp((0.25 * (m * m)));
	} else if (n <= 54.0) {
		tmp = exp(-l);
	} else {
		tmp = 1.0 / exp((0.25 * (n * 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) :: tmp
    if (n <= 2.2d-231) then
        tmp = 1.0d0 / exp((0.25d0 * (m * m)))
    else if (n <= 54.0d0) then
        tmp = exp(-l)
    else
        tmp = 1.0d0 / exp((0.25d0 * (n * n)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 2.2e-231) {
		tmp = 1.0 / Math.exp((0.25 * (m * m)));
	} else if (n <= 54.0) {
		tmp = Math.exp(-l);
	} else {
		tmp = 1.0 / Math.exp((0.25 * (n * n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if n <= 2.2e-231:
		tmp = 1.0 / math.exp((0.25 * (m * m)))
	elif n <= 54.0:
		tmp = math.exp(-l)
	else:
		tmp = 1.0 / math.exp((0.25 * (n * n)))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (n <= 2.2e-231)
		tmp = Float64(1.0 / exp(Float64(0.25 * Float64(m * m))));
	elseif (n <= 54.0)
		tmp = exp(Float64(-l));
	else
		tmp = Float64(1.0 / exp(Float64(0.25 * Float64(n * n))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (n <= 2.2e-231)
		tmp = 1.0 / exp((0.25 * (m * m)));
	elseif (n <= 54.0)
		tmp = exp(-l);
	else
		tmp = 1.0 / exp((0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 2.2e-231], N[(1.0 / N[Exp[N[(0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 54.0], N[Exp[(-l)], $MachinePrecision], N[(1.0 / N[Exp[N[(0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n \leq 2.2 \cdot 10^{-231}:\\
\;\;\;\;\frac{1}{e^{0.25 \cdot \left(m \cdot m\right)}}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;e^{-\ell}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{0.25 \cdot \left(n \cdot n\right)}}\\


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

    1. Initial program 77.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. Simplified77.1%

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

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

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

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

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

      \[\leadsto \frac{1}{e^{\color{blue}{0.25 \cdot {m}^{2}}}} \]
    8. Step-by-step derivation
      1. *-commutative56.3%

        \[\leadsto \frac{1}{e^{\color{blue}{{m}^{2} \cdot 0.25}}} \]
      2. unpow256.3%

        \[\leadsto \frac{1}{e^{\color{blue}{\left(m \cdot m\right)} \cdot 0.25}} \]
    9. Simplified56.3%

      \[\leadsto \frac{1}{e^{\color{blue}{\left(m \cdot m\right) \cdot 0.25}}} \]

    if 2.20000000000000009e-231 < n < 54

    1. Initial program 89.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. Simplified89.1%

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

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

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

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

      \[\leadsto \frac{\cos M}{e^{\color{blue}{\ell}}} \]
    7. Taylor expanded in M around 0 56.5%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    8. Step-by-step derivation
      1. rec-exp56.5%

        \[\leadsto \color{blue}{e^{-\ell}} \]
    9. Simplified56.5%

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

    if 54 < n

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

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

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

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

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

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

      \[\leadsto \frac{1}{e^{\color{blue}{0.25 \cdot {n}^{2}}}} \]
    8. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \frac{1}{e^{\color{blue}{{n}^{2} \cdot 0.25}}} \]
      2. unpow2100.0%

        \[\leadsto \frac{1}{e^{\color{blue}{\left(n \cdot n\right)} \cdot 0.25}} \]
    9. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 2.2 \cdot 10^{-231}:\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \]

Alternative 7: 35.3% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 77.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. Simplified77.9%

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

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

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

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

    \[\leadsto \frac{\cos M}{e^{\color{blue}{\ell}}} \]
  7. Taylor expanded in M around 0 40.3%

    \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
  8. Step-by-step derivation
    1. rec-exp40.3%

      \[\leadsto \color{blue}{e^{-\ell}} \]
  9. Simplified40.3%

    \[\leadsto \color{blue}{e^{-\ell}} \]
  10. Final simplification40.3%

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

Alternative 8: 7.0% 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.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. Simplified77.9%

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

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

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

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

    \[\leadsto \frac{\cos M}{e^{\color{blue}{\ell}}} \]
  7. Taylor expanded in l around 0 7.3%

    \[\leadsto \color{blue}{\cos M} \]
  8. Final simplification7.3%

    \[\leadsto \cos M \]

Alternative 9: 7.0% 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.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. Simplified77.9%

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

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

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

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

    \[\leadsto \frac{\cos M}{e^{\color{blue}{\ell}}} \]
  7. Taylor expanded in l around 0 7.3%

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

    \[\leadsto \color{blue}{1} \]
  9. Final simplification7.3%

    \[\leadsto 1 \]

Reproduce

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