Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.1% → 96.7%
Time: 14.4s
Alternatives: 10
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 76.1% accurate, 1.0× speedup?

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

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

Alternative 1: 96.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

Alternative 2: 95.6% accurate, 1.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -2.9000000000000001e28 or 30 < M

    1. Initial program 76.4%

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

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

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

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

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

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

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

    if -2.9000000000000001e28 < M < 30

    1. Initial program 76.9%

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

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

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

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

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

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

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

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

Alternative 3: 95.5% accurate, 1.3× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -1.75e28 or 27 < M

    1. Initial program 76.4%

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

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

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

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

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

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

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

    if -1.75e28 < M < 27

    1. Initial program 76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 64.1% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq -2.4 \cdot 10^{-34}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

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


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

    1. Initial program 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4100 < m < -2.39999999999999991e-34

    1. Initial program 88.9%

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

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

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

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

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

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

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

    if -2.39999999999999991e-34 < m

    1. Initial program 78.9%

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-0.25 \cdot \color{blue}{\left(n \cdot n\right)}} \]
    8. Applied egg-rr54.9%

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

Alternative 5: 64.0% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;m \leq -3.3 \cdot 10^{-38}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

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


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

    1. Initial program 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4100 < m < -3.3000000000000002e-38

    1. Initial program 90.9%

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

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

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

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

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

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

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

    if -3.3000000000000002e-38 < m

    1. Initial program 78.6%

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-0.25 \cdot \color{blue}{\left(n \cdot n\right)}} \]
    8. Applied egg-rr55.5%

      \[\leadsto \cos M \cdot e^{-0.25 \cdot \color{blue}{\left(n \cdot n\right)}} \]
    9. Taylor expanded in M around 0 55.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -4100:\\ \;\;\;\;e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;m \leq -3.3 \cdot 10^{-38}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 64.5% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4100 < m

    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. Add Preprocessing
    3. Taylor expanded in K around 0 95.8%

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

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

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

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

        \[\leadsto \cos M \cdot e^{-0.25 \cdot \color{blue}{\left(n \cdot n\right)}} \]
    8. Applied egg-rr53.3%

      \[\leadsto \cos M \cdot e^{-0.25 \cdot \color{blue}{\left(n \cdot n\right)}} \]
    9. Taylor expanded in M around 0 53.3%

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

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

Alternative 7: 86.8% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 53.1% accurate, 4.0× speedup?

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

\\
e^{-0.25 \cdot \left(n \cdot n\right)}
\end{array}
Derivation
  1. Initial program 76.7%

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{-0.25 \cdot \color{blue}{\left(n \cdot n\right)}} \]
  8. Applied egg-rr53.2%

    \[\leadsto \cos M \cdot e^{-0.25 \cdot \color{blue}{\left(n \cdot n\right)}} \]
  9. Taylor expanded in M around 0 53.2%

    \[\leadsto \color{blue}{1} \cdot e^{-0.25 \cdot \left(n \cdot n\right)} \]
  10. Final simplification53.2%

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

Alternative 9: 6.6% 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 76.7%

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

    \[\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-neg32.9%

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

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

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

      \[\leadsto \color{blue}{\cos M} \]
  9. Simplified9.0%

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

Alternative 10: 6.6% 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 76.7%

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

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

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

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

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

    \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]
  8. Step-by-step derivation
    1. exp-prod53.2%

      \[\leadsto \color{blue}{{\left(e^{-0.25}\right)}^{\left({n}^{2}\right)}} \]
  9. Simplified53.2%

    \[\leadsto \color{blue}{{\left(e^{-0.25}\right)}^{\left({n}^{2}\right)}} \]
  10. Taylor expanded in n around 0 9.0%

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

Reproduce

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