Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.2% → 96.7%
Time: 22.5s
Alternatives: 8
Speedup: 1.9×

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 8 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.2% 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 78.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 97.7%

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

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

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

    \[\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: 76.3% accurate, 1.9× speedup?

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

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

\mathbf{elif}\;m \leq 5.5 \cdot 10^{-216}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \ell}\\

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


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

    1. Initial program 71.0%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 98.6%

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

    if -1560 < m < 5.49999999999999991e-216

    1. Initial program 87.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 m around 0 87.3%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(-\left(n \cdot 0.5 - M\right) \cdot \left(\left(n \cdot 0.5 - M\right) + m\right)\right) - \ell} \]
    8. Step-by-step derivation
      1. cos-neg96.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)} \]
    9. Simplified96.3%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    11. Step-by-step derivation
      1. mul-1-neg80.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{-\left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
      2. mul-1-neg80.7%

        \[\leadsto \cos M \cdot e^{-\left(\ell + \color{blue}{\left(-M \cdot \left(m - M\right)\right)}\right)} \]
      3. unsub-neg80.7%

        \[\leadsto \cos M \cdot e^{-\color{blue}{\left(\ell - M \cdot \left(m - M\right)\right)}} \]
    12. Simplified80.7%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\left(\ell - M \cdot \left(m - M\right)\right)}} \]

    if 5.49999999999999991e-216 < m

    1. Initial program 77.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 m around 0 67.1%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(-\left(n \cdot 0.5 - M\right) \cdot \left(\left(n \cdot 0.5 - M\right) + m\right)\right) - \ell} \]
    8. Step-by-step derivation
      1. cos-neg98.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)} \]
    9. Simplified82.3%

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

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

        \[\leadsto \cos M \cdot e^{\left(-0.5 \cdot \left(n \cdot \left(m + \color{blue}{n \cdot 0.5}\right)\right)\right) - \ell} \]
    12. Simplified74.1%

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

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

Alternative 3: 88.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := M - n \cdot 0.5\\ \mathbf{if}\;m \leq -5 \cdot 10^{+17}:\\ \;\;\;\;e^{-0.25 \cdot {m}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - t\_0\right) \cdot t\_0 - \ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- M (* n 0.5))))
   (if (<= m -5e+17)
     (exp (* -0.25 (pow m 2.0)))
     (* (cos M) (exp (- (* (- m t_0) t_0) l))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = M - (n * 0.5);
	double tmp;
	if (m <= -5e+17) {
		tmp = exp((-0.25 * pow(m, 2.0)));
	} else {
		tmp = cos(M) * exp((((m - t_0) * t_0) - 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) :: t_0
    real(8) :: tmp
    t_0 = m_1 - (n * 0.5d0)
    if (m <= (-5d+17)) then
        tmp = exp(((-0.25d0) * (m ** 2.0d0)))
    else
        tmp = cos(m_1) * exp((((m - t_0) * t_0) - l))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = M - (n * 0.5);
	double tmp;
	if (m <= -5e+17) {
		tmp = Math.exp((-0.25 * Math.pow(m, 2.0)));
	} else {
		tmp = Math.cos(M) * Math.exp((((m - t_0) * t_0) - l));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = M - (n * 0.5)
	tmp = 0
	if m <= -5e+17:
		tmp = math.exp((-0.25 * math.pow(m, 2.0)))
	else:
		tmp = math.cos(M) * math.exp((((m - t_0) * t_0) - l))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(M - Float64(n * 0.5))
	tmp = 0.0
	if (m <= -5e+17)
		tmp = exp(Float64(-0.25 * (m ^ 2.0)));
	else
		tmp = Float64(cos(M) * exp(Float64(Float64(Float64(m - t_0) * t_0) - l)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = M - (n * 0.5);
	tmp = 0.0;
	if (m <= -5e+17)
		tmp = exp((-0.25 * (m ^ 2.0)));
	else
		tmp = cos(M) * exp((((m - t_0) * t_0) - l));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(M - N[(n * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[m, -5e+17], N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(N[(m - t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := M - n \cdot 0.5\\
\mathbf{if}\;m \leq -5 \cdot 10^{+17}:\\
\;\;\;\;e^{-0.25 \cdot {m}^{2}}\\

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


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

    1. Initial program 70.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 98.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-neg98.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. Simplified98.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 inf 98.6%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 98.6%

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

    if -5e17 < m

    1. Initial program 81.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 m around 0 76.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(-\left(n \cdot 0.5 - M\right) \cdot \left(\left(n \cdot 0.5 - M\right) + m\right)\right) - \ell} \]
    8. Step-by-step derivation
      1. cos-neg97.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)} \]
    9. Simplified88.5%

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

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

Alternative 4: 55.9% accurate, 1.9× speedup?

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

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

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

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


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

    1. Initial program 71.0%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 98.6%

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

    if -2.89999999999999991 < m < 8.0000000000000002e-179

    1. Initial program 88.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 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 l around inf 48.6%

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

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

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

    if 8.0000000000000002e-179 < m

    1. Initial program 75.5%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(-\left(n \cdot 0.5 - M\right) \cdot \left(\left(n \cdot 0.5 - M\right) + m\right)\right) - \ell} \]
    8. Step-by-step derivation
      1. cos-neg98.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)} \]
    9. Simplified80.9%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{m \cdot \left(M - 0.5 \cdot n\right)}} \]
    11. Step-by-step derivation
      1. *-commutative52.0%

        \[\leadsto \cos M \cdot e^{m \cdot \left(M - \color{blue}{n \cdot 0.5}\right)} \]
    12. Simplified52.0%

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

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

Alternative 5: 73.4% accurate, 1.9× speedup?

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

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

\mathbf{elif}\;m \leq 1.25 \cdot 10^{-6}:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(m - M\right) - \ell}\\

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


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

    1. Initial program 71.0%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 98.6%

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

    if -1560 < m < 1.2500000000000001e-6

    1. Initial program 87.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 m around 0 87.9%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(-\left(n \cdot 0.5 - M\right) \cdot \left(\left(n \cdot 0.5 - M\right) + m\right)\right) - \ell} \]
    8. 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)} \]
    9. Simplified96.1%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
    11. Step-by-step derivation
      1. mul-1-neg80.6%

        \[\leadsto \cos M \cdot e^{\color{blue}{-\left(\ell + -1 \cdot \left(M \cdot \left(m - M\right)\right)\right)}} \]
      2. mul-1-neg80.6%

        \[\leadsto \cos M \cdot e^{-\left(\ell + \color{blue}{\left(-M \cdot \left(m - M\right)\right)}\right)} \]
      3. unsub-neg80.6%

        \[\leadsto \cos M \cdot e^{-\color{blue}{\left(\ell - M \cdot \left(m - M\right)\right)}} \]
    12. Simplified80.6%

      \[\leadsto \cos M \cdot e^{\color{blue}{-\left(\ell - M \cdot \left(m - M\right)\right)}} \]

    if 1.2500000000000001e-6 < m

    1. Initial program 68.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 m around 0 51.1%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(-\left(n \cdot 0.5 - M\right) \cdot \left(\left(n \cdot 0.5 - M\right) + m\right)\right) - \ell} \]
    8. 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)} \]
    9. Simplified72.6%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{m \cdot \left(M - 0.5 \cdot n\right)}} \]
    11. Step-by-step derivation
      1. *-commutative58.1%

        \[\leadsto \cos M \cdot e^{m \cdot \left(M - \color{blue}{n \cdot 0.5}\right)} \]
    12. Simplified58.1%

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

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

Alternative 6: 69.2% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 69.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 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)} \]
    4. 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)} \]
    5. 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)} \]
    6. Taylor expanded in m around inf 97.8%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 97.8%

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

    if -2.89999999999999991 < m < 47

    1. Initial program 87.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 45.7%

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

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

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

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

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

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

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

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

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

Alternative 7: 69.5% accurate, 2.0× speedup?

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

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


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

    1. Initial program 69.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 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)} \]
    4. 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)} \]
    5. 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)} \]
    6. Taylor expanded in m around inf 97.8%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 97.8%

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

    if -2.89999999999999991 < m < 47

    1. Initial program 87.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 l around inf 47.9%

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

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

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

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

Alternative 8: 34.9% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 78.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 l around inf 32.0%

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

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

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

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

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

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

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

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

    \[\leadsto e^{-\ell} \]
  11. Add Preprocessing

Reproduce

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