Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 77.0% → 96.9%
Time: 19.3s
Alternatives: 9
Speedup: 1.4×

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: 77.0% accurate, 1.0× speedup?

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

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

Alternative 1: 96.9% 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 74.9%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Taylor expanded in K around 0 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)} \]
  3. 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)} \]
  4. 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)} \]
  5. Final simplification96.9%

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

Alternative 2: 77.9% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -1260000 \lor \neg \left(m \leq 53\right):\\
\;\;\;\;\cos M \cdot e^{{m}^{2} \cdot -0.25}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -1.26e6 or 53 < m

    1. Initial program 71.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. Taylor expanded in K around 0 99.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)} \]
    3. Step-by-step derivation
      1. cos-neg99.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)} \]
    4. Simplified99.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. Taylor expanded in m around inf 99.2%

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

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

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

    if -1.26e6 < m < 53

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

      \[\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)} \]
    3. Step-by-step derivation
      1. cos-neg94.6%

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

      \[\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. Taylor expanded in M around inf 63.2%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
    7. Simplified63.2%

      \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1260000 \lor \neg \left(m \leq 53\right):\\ \;\;\;\;\cos M \cdot e^{{m}^{2} \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \end{array} \]

Alternative 3: 65.7% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 4.2 \cdot 10^{-177}:\\
\;\;\;\;\cos M \cdot e^{{m}^{2} \cdot -0.25}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\


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

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

      \[\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)} \]
    3. Step-by-step derivation
      1. cos-neg95.3%

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

      \[\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. Taylor expanded in m around inf 55.4%

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

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    7. Simplified55.4%

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

    if 4.20000000000000002e-177 < n < 54

    1. Initial program 85.3%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Taylor expanded in K around 0 97.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)} \]
    3. Step-by-step derivation
      1. cos-neg97.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)} \]
    4. Simplified97.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. Taylor expanded in M around inf 59.7%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
    7. Simplified59.7%

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

    if 54 < n

    1. Initial program 69.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Taylor expanded in 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)} \]
    3. 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)} \]
    4. 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)} \]
    5. Taylor expanded in n around inf 98.7%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification69.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 4.2 \cdot 10^{-177}:\\ \;\;\;\;\cos M \cdot e^{{m}^{2} \cdot -0.25}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot {n}^{2}}\\ \end{array} \]

Alternative 4: 66.7% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 720:\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 720

    1. Initial program 74.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. Taylor expanded in K around 0 95.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)} \]
    3. Step-by-step derivation
      1. cos-neg95.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)} \]
    4. Simplified95.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. Taylor expanded in M around inf 53.9%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
    7. Simplified53.9%

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

    if 720 < l

    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. Taylor expanded in l around inf 76.7%

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{\cos M \cdot e^{-\ell}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 720:\\ \;\;\;\;\cos M \cdot e^{-{M}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]

Alternative 5: 35.4% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 7.6 \cdot 10^{-21}:\\
\;\;\;\;-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(n \cdot K\right) - M\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 7.5999999999999995e-21

    1. Initial program 75.3%

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    3. Step-by-step derivation
      1. *-commutative40.0%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    4. Simplified40.0%

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

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

        \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
      2. associate-*r*7.2%

        \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right) - M\right) + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)} \]
      3. *-commutative7.2%

        \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right) - M\right) + -0.5 \cdot \left(\color{blue}{\left(m \cdot K\right)} \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right) \]
      4. *-commutative7.2%

        \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right) - M\right) + -0.5 \cdot \left(\left(m \cdot K\right) \cdot \sin \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right)\right) \]
    7. Simplified7.2%

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(n \cdot K\right) - M\right) + -0.5 \cdot \left(\left(m \cdot K\right) \cdot \sin \left(0.5 \cdot \left(n \cdot K\right) - M\right)\right)} \]
    8. Taylor expanded in K around inf 17.1%

      \[\leadsto \color{blue}{-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]

    if 7.5999999999999995e-21 < l

    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. Taylor expanded in l around inf 70.9%

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

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

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

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

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
    7. Simplified92.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 7.6 \cdot 10^{-21}:\\ \;\;\;\;-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(n \cdot K\right) - M\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]

Alternative 6: 19.7% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;m \leq -2.9 \cdot 10^{-19}:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(n \cdot \sin M\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(n \cdot K\right) - M\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= m -2.9e-19)
   (* 0.5 (* K (* n (sin M))))
   (* -0.5 (* K (* m (sin (- (* 0.5 (* n K)) M)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (m <= -2.9e-19) {
		tmp = 0.5 * (K * (n * sin(M)));
	} else {
		tmp = -0.5 * (K * (m * sin(((0.5 * (n * K)) - M))));
	}
	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 <= (-2.9d-19)) then
        tmp = 0.5d0 * (k * (n * sin(m_1)))
    else
        tmp = (-0.5d0) * (k * (m * sin(((0.5d0 * (n * k)) - m_1))))
    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-19) {
		tmp = 0.5 * (K * (n * Math.sin(M)));
	} else {
		tmp = -0.5 * (K * (m * Math.sin(((0.5 * (n * K)) - M))));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if m <= -2.9e-19:
		tmp = 0.5 * (K * (n * math.sin(M)))
	else:
		tmp = -0.5 * (K * (m * math.sin(((0.5 * (n * K)) - M))))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (m <= -2.9e-19)
		tmp = Float64(0.5 * Float64(K * Float64(n * sin(M))));
	else
		tmp = Float64(-0.5 * Float64(K * Float64(m * sin(Float64(Float64(0.5 * Float64(n * K)) - M)))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (m <= -2.9e-19)
		tmp = 0.5 * (K * (n * sin(M)));
	else
		tmp = -0.5 * (K * (m * sin(((0.5 * (n * K)) - M))));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -2.9e-19], N[(0.5 * N[(K * N[(n * N[Sin[M], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(K * N[(m * N[Sin[N[(N[(0.5 * N[(n * K), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;m \leq -2.9 \cdot 10^{-19}:\\
\;\;\;\;0.5 \cdot \left(K \cdot \left(n \cdot \sin M\right)\right)\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(n \cdot K\right) - M\right)\right)\right)\\


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

    1. Initial program 71.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. Taylor expanded in m around inf 62.9%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    3. Step-by-step derivation
      1. *-commutative62.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(n \cdot \sin \left(-M\right)\right)\right) \]
      2. *-commutative2.7%

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

        \[\leadsto \cos M + -0.5 \cdot \left(K \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot n\right)\right) \]
    10. Simplified2.7%

      \[\leadsto \color{blue}{\cos M + -0.5 \cdot \left(K \cdot \left(\left(-\sin M\right) \cdot n\right)\right)} \]
    11. Taylor expanded in K around inf 18.7%

      \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(n \cdot \sin M\right)\right)} \]

    if -2.9e-19 < m

    1. Initial program 76.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. Taylor expanded in m around inf 32.3%

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

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

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

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

        \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) + -0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right) \]
      2. associate-*r*7.3%

        \[\leadsto \cos \left(0.5 \cdot \left(n \cdot K\right) - M\right) + -0.5 \cdot \color{blue}{\left(\left(K \cdot m\right) \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)} \]
      3. *-commutative7.3%

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

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

      \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(n \cdot K\right) - M\right) + -0.5 \cdot \left(\left(m \cdot K\right) \cdot \sin \left(0.5 \cdot \left(n \cdot K\right) - M\right)\right)} \]
    8. Taylor expanded in K around inf 20.6%

      \[\leadsto \color{blue}{-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(K \cdot n\right) - M\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification20.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -2.9 \cdot 10^{-19}:\\ \;\;\;\;0.5 \cdot \left(K \cdot \left(n \cdot \sin M\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(0.5 \cdot \left(n \cdot K\right) - M\right)\right)\right)\\ \end{array} \]

Alternative 7: 20.6% accurate, 4.0× speedup?

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

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

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

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  4. Simplified40.3%

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

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

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
  7. Simplified6.4%

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

    \[\leadsto \color{blue}{\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(n \cdot \sin \left(-M\right)\right)\right)} \]
  9. Step-by-step derivation
    1. cos-neg6.0%

      \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(n \cdot \sin \left(-M\right)\right)\right) \]
    2. *-commutative6.0%

      \[\leadsto \cos M + -0.5 \cdot \left(K \cdot \color{blue}{\left(\sin \left(-M\right) \cdot n\right)}\right) \]
    3. sin-neg6.0%

      \[\leadsto \cos M + -0.5 \cdot \left(K \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot n\right)\right) \]
  10. Simplified6.0%

    \[\leadsto \color{blue}{\cos M + -0.5 \cdot \left(K \cdot \left(\left(-\sin M\right) \cdot n\right)\right)} \]
  11. Taylor expanded in K around inf 19.2%

    \[\leadsto \color{blue}{0.5 \cdot \left(K \cdot \left(n \cdot \sin M\right)\right)} \]
  12. Final simplification19.2%

    \[\leadsto 0.5 \cdot \left(K \cdot \left(n \cdot \sin M\right)\right) \]

Alternative 8: 6.7% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \cos \left(-M\right) \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(Float64(-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 \left(-M\right)
\end{array}
Derivation
  1. Initial program 74.9%

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

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  4. Simplified40.3%

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

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

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
  7. Simplified6.4%

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

    \[\leadsto \cos \color{blue}{\left(-1 \cdot M\right)} \]
  9. Step-by-step derivation
    1. neg-mul-16.6%

      \[\leadsto \cos \color{blue}{\left(-M\right)} \]
  10. Simplified6.6%

    \[\leadsto \cos \color{blue}{\left(-M\right)} \]
  11. Final simplification6.6%

    \[\leadsto \cos \left(-M\right) \]

Alternative 9: 6.7% 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 74.9%

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

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  4. Simplified40.3%

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

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

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(n \cdot K\right)} - M\right) \]
  7. Simplified6.4%

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

    \[\leadsto \color{blue}{\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(n \cdot \sin \left(-M\right)\right)\right)} \]
  9. Step-by-step derivation
    1. cos-neg6.0%

      \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(n \cdot \sin \left(-M\right)\right)\right) \]
    2. *-commutative6.0%

      \[\leadsto \cos M + -0.5 \cdot \left(K \cdot \color{blue}{\left(\sin \left(-M\right) \cdot n\right)}\right) \]
    3. sin-neg6.0%

      \[\leadsto \cos M + -0.5 \cdot \left(K \cdot \left(\color{blue}{\left(-\sin M\right)} \cdot n\right)\right) \]
  10. Simplified6.0%

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

    \[\leadsto \color{blue}{1} \]
  12. Final simplification6.6%

    \[\leadsto 1 \]

Reproduce

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