Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.5% → 96.5%
Time: 26.4s
Alternatives: 8
Speedup: 2.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.5% 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.5% accurate, 1.0× speedup?

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

\\
\cos M \cdot e^{\left(\left|n - m\right| - \ell\right) - {\left(\left(n + m\right) \cdot 0.5 - M\right)}^{2}}
\end{array}
Derivation
  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 K around 0 97.5%

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
    7. unpow297.5%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    8. cancel-sign-sub-inv97.5%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
  4. Simplified97.5%

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

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

Alternative 2: 68.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -2.55 \cdot 10^{-163}:\\
\;\;\;\;\cos M \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;e^{\left|n - m\right| - \left(\ell + M \cdot M\right)} \cdot \cos \left(n \cdot \left(0.5 \cdot K\right) - M\right)\\

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


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

    1. Initial program 72.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 98.9%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow298.9%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv98.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified98.9%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    7. Simplified54.9%

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

    if -2.54999999999999995e-163 < n < 54

    1. Initial program 82.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. Step-by-step derivation
      1. +-commutative82.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 54 < n

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow2100.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv100.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified100.0%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
    7. Simplified97.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -2.55 \cdot 10^{-163}:\\ \;\;\;\;\cos M \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;e^{\left|n - m\right| - \left(\ell + M \cdot M\right)} \cdot \cos \left(n \cdot \left(0.5 \cdot K\right) - M\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \]

Alternative 3: 77.4% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\
t_1 := \cos M \cdot e^{-M \cdot M}\\
\mathbf{if}\;M \leq -8.2 \cdot 10^{-5}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;M \leq -4.9 \cdot 10^{-183}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;M \leq 7.2 \cdot 10^{-248}:\\
\;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\

\mathbf{elif}\;M \leq 27:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -8.20000000000000009e-5 or 27 < M

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow299.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv99.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified99.3%

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

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

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

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-out97.9%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    7. Simplified97.9%

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

    if -8.20000000000000009e-5 < M < -4.9e-183 or 7.19999999999999969e-248 < M < 27

    1. Initial program 65.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 97.8%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow297.8%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv97.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified97.8%

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    7. Simplified62.4%

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

    if -4.9e-183 < M < 7.19999999999999969e-248

    1. Initial program 72.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 91.2%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow291.2%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv91.2%

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    8. Taylor expanded in M around 0 33.2%

      \[\leadsto \color{blue}{e^{-\ell} + -0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*33.2%

        \[\leadsto e^{-\ell} + \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. distribute-rgt1-in42.8%

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

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)} + 1\right) \cdot e^{-\ell} \]
    10. Simplified42.8%

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

      \[\leadsto \color{blue}{-0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    12. Step-by-step derivation
      1. associate-*r*78.8%

        \[\leadsto \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. unpow278.8%

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot e^{-\ell} \]
    13. Simplified78.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -8.2 \cdot 10^{-5}:\\ \;\;\;\;\cos M \cdot e^{-M \cdot M}\\ \mathbf{elif}\;M \leq -4.9 \cdot 10^{-183}:\\ \;\;\;\;\cos M \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;M \leq 7.2 \cdot 10^{-248}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 27:\\ \;\;\;\;\cos M \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-M \cdot M}\\ \end{array} \]

Alternative 4: 72.6% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
t_1 := \left(M \cdot M\right) \cdot -0.5\\
t_2 := \cos M \cdot e^{-M \cdot M}\\
\mathbf{if}\;M \leq -4.45 \cdot 10^{-45}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;M \leq -8.2 \cdot 10^{-169}:\\
\;\;\;\;t_0 \cdot \left(t_1 + 1\right)\\

\mathbf{elif}\;M \leq 1.65 \cdot 10^{-75}:\\
\;\;\;\;t_1 \cdot t_0\\

\mathbf{elif}\;M \leq 26:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if M < -4.45000000000000017e-45 or 26 < M

    1. Initial program 81.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 99.3%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow299.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv99.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified99.3%

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

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

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

        \[\leadsto \cos M \cdot e^{-\color{blue}{M \cdot M}} \]
      3. distribute-rgt-neg-out92.8%

        \[\leadsto \cos M \cdot e^{\color{blue}{M \cdot \left(-M\right)}} \]
    7. Simplified92.8%

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

    if -4.45000000000000017e-45 < M < -8.1999999999999996e-169

    1. Initial program 66.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 K around 0 100.0%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow2100.0%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv100.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified100.0%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    8. Taylor expanded in M around 0 34.4%

      \[\leadsto \color{blue}{e^{-\ell} + -0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*34.4%

        \[\leadsto e^{-\ell} + \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. distribute-rgt1-in56.8%

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

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)} + 1\right) \cdot e^{-\ell} \]
    10. Simplified56.8%

      \[\leadsto \color{blue}{\left(-0.5 \cdot \left(M \cdot M\right) + 1\right) \cdot e^{-\ell}} \]

    if -8.1999999999999996e-169 < M < 1.65e-75

    1. Initial program 63.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 92.3%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow292.3%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv92.3%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified92.3%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    8. Taylor expanded in M around 0 28.8%

      \[\leadsto \color{blue}{e^{-\ell} + -0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*28.8%

        \[\leadsto e^{-\ell} + \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. distribute-rgt1-in34.7%

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

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)} + 1\right) \cdot e^{-\ell} \]
    10. Simplified34.7%

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

      \[\leadsto \color{blue}{-0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    12. Step-by-step derivation
      1. associate-*r*68.9%

        \[\leadsto \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. unpow268.9%

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot e^{-\ell} \]
    13. Simplified68.9%

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

    if 1.65e-75 < M < 26

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow299.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv99.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified99.7%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    8. Taylor expanded in M around 0 46.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -4.45 \cdot 10^{-45}:\\ \;\;\;\;\cos M \cdot e^{-M \cdot M}\\ \mathbf{elif}\;M \leq -8.2 \cdot 10^{-169}:\\ \;\;\;\;e^{-\ell} \cdot \left(\left(M \cdot M\right) \cdot -0.5 + 1\right)\\ \mathbf{elif}\;M \leq 1.65 \cdot 10^{-75}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\ \mathbf{elif}\;M \leq 26:\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-M \cdot M}\\ \end{array} \]

Alternative 5: 39.7% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ \mathbf{if}\;\ell \leq -3.05 \cdot 10^{-33} \lor \neg \left(\ell \leq 2.25 \cdot 10^{-64}\right):\\ \;\;\;\;\cos M \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t_0\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- l))))
   (if (or (<= l -3.05e-33) (not (<= l 2.25e-64)))
     (* (cos M) t_0)
     (* (* (* M M) -0.5) t_0))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(-l);
	double tmp;
	if ((l <= -3.05e-33) || !(l <= 2.25e-64)) {
		tmp = cos(M) * t_0;
	} else {
		tmp = ((M * M) * -0.5) * t_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) :: t_0
    real(8) :: tmp
    t_0 = exp(-l)
    if ((l <= (-3.05d-33)) .or. (.not. (l <= 2.25d-64))) then
        tmp = cos(m_1) * t_0
    else
        tmp = ((m_1 * m_1) * (-0.5d0)) * t_0
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(-l);
	double tmp;
	if ((l <= -3.05e-33) || !(l <= 2.25e-64)) {
		tmp = Math.cos(M) * t_0;
	} else {
		tmp = ((M * M) * -0.5) * t_0;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp(-l)
	tmp = 0
	if (l <= -3.05e-33) or not (l <= 2.25e-64):
		tmp = math.cos(M) * t_0
	else:
		tmp = ((M * M) * -0.5) * t_0
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(-l))
	tmp = 0.0
	if ((l <= -3.05e-33) || !(l <= 2.25e-64))
		tmp = Float64(cos(M) * t_0);
	else
		tmp = Float64(Float64(Float64(M * M) * -0.5) * t_0);
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(-l);
	tmp = 0.0;
	if ((l <= -3.05e-33) || ~((l <= 2.25e-64)))
		tmp = cos(M) * t_0;
	else
		tmp = ((M * M) * -0.5) * t_0;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, If[Or[LessEqual[l, -3.05e-33], N[Not[LessEqual[l, 2.25e-64]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[(N[(M * M), $MachinePrecision] * -0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
\mathbf{if}\;\ell \leq -3.05 \cdot 10^{-33} \lor \neg \left(\ell \leq 2.25 \cdot 10^{-64}\right):\\
\;\;\;\;\cos M \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3.0500000000000001e-33 or 2.25000000000000005e-64 < l

    1. Initial program 75.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 K around 0 98.4%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow298.4%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv98.4%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified98.4%

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

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

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

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

    if -3.0500000000000001e-33 < l < 2.25000000000000005e-64

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow296.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv96.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified96.7%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    8. Taylor expanded in M around 0 5.9%

      \[\leadsto \color{blue}{e^{-\ell} + -0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*5.9%

        \[\leadsto e^{-\ell} + \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. distribute-rgt1-in5.9%

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

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)} + 1\right) \cdot e^{-\ell} \]
    10. Simplified5.9%

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

      \[\leadsto \color{blue}{-0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    12. Step-by-step derivation
      1. associate-*r*26.0%

        \[\leadsto \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. unpow226.0%

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot e^{-\ell} \]
    13. Simplified26.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.05 \cdot 10^{-33} \lor \neg \left(\ell \leq 2.25 \cdot 10^{-64}\right):\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\ \end{array} \]

Alternative 6: 39.2% accurate, 3.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-\ell}\\ \mathbf{if}\;\ell \leq -7.2 \cdot 10^{-33} \lor \neg \left(\ell \leq 2.45 \cdot 10^{-64}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t_0\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- l))))
   (if (or (<= l -7.2e-33) (not (<= l 2.45e-64)))
     t_0
     (* (* (* M M) -0.5) t_0))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(-l);
	double tmp;
	if ((l <= -7.2e-33) || !(l <= 2.45e-64)) {
		tmp = t_0;
	} else {
		tmp = ((M * M) * -0.5) * t_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) :: t_0
    real(8) :: tmp
    t_0 = exp(-l)
    if ((l <= (-7.2d-33)) .or. (.not. (l <= 2.45d-64))) then
        tmp = t_0
    else
        tmp = ((m_1 * m_1) * (-0.5d0)) * t_0
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(-l);
	double tmp;
	if ((l <= -7.2e-33) || !(l <= 2.45e-64)) {
		tmp = t_0;
	} else {
		tmp = ((M * M) * -0.5) * t_0;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp(-l)
	tmp = 0
	if (l <= -7.2e-33) or not (l <= 2.45e-64):
		tmp = t_0
	else:
		tmp = ((M * M) * -0.5) * t_0
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(-l))
	tmp = 0.0
	if ((l <= -7.2e-33) || !(l <= 2.45e-64))
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(M * M) * -0.5) * t_0);
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(-l);
	tmp = 0.0;
	if ((l <= -7.2e-33) || ~((l <= 2.45e-64)))
		tmp = t_0;
	else
		tmp = ((M * M) * -0.5) * t_0;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[(-l)], $MachinePrecision]}, If[Or[LessEqual[l, -7.2e-33], N[Not[LessEqual[l, 2.45e-64]], $MachinePrecision]], t$95$0, N[(N[(N[(M * M), $MachinePrecision] * -0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-\ell}\\
\mathbf{if}\;\ell \leq -7.2 \cdot 10^{-33} \lor \neg \left(\ell \leq 2.45 \cdot 10^{-64}\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -7.20000000000000068e-33 or 2.4500000000000001e-64 < l

    1. Initial program 75.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 K around 0 98.4%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow298.4%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv98.4%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified98.4%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    8. Taylor expanded in M around 0 59.1%

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

    if -7.20000000000000068e-33 < l < 2.4500000000000001e-64

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
      7. unpow296.7%

        \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
      8. cancel-sign-sub-inv96.7%

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    4. Simplified96.7%

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
    8. Taylor expanded in M around 0 5.9%

      \[\leadsto \color{blue}{e^{-\ell} + -0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*5.9%

        \[\leadsto e^{-\ell} + \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. distribute-rgt1-in5.9%

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

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)} + 1\right) \cdot e^{-\ell} \]
    10. Simplified5.9%

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

      \[\leadsto \color{blue}{-0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    12. Step-by-step derivation
      1. associate-*r*26.0%

        \[\leadsto \color{blue}{\left(-0.5 \cdot {M}^{2}\right) \cdot e^{-\ell}} \]
      2. unpow226.0%

        \[\leadsto \left(-0.5 \cdot \color{blue}{\left(M \cdot M\right)}\right) \cdot e^{-\ell} \]
    13. Simplified26.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.2 \cdot 10^{-33} \lor \neg \left(\ell \leq 2.45 \cdot 10^{-64}\right):\\ \;\;\;\;e^{-\ell}\\ \mathbf{else}:\\ \;\;\;\;\left(\left(M \cdot M\right) \cdot -0.5\right) \cdot e^{-\ell}\\ \end{array} \]

Alternative 7: 34.7% 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 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 K around 0 97.5%

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
    7. unpow297.5%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    8. cancel-sign-sub-inv97.5%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
  4. Simplified97.5%

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  8. Taylor expanded in M around 0 32.6%

    \[\leadsto \color{blue}{e^{-\ell}} \]
  9. Final simplification32.6%

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

Alternative 8: 6.9% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 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 K around 0 97.5%

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\color{blue}{\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}}^{2}} \]
    7. unpow297.5%

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\mathsf{fma}\left(m + n, 0.5, -M\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
    8. cancel-sign-sub-inv97.5%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(\left|m - n\right| - \ell\right) + \left(-\mathsf{fma}\left(m + n, 0.5, -M\right)\right) \cdot \mathsf{fma}\left(m + n, 0.5, -M\right)}} \]
  4. Simplified97.5%

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

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

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

    \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
  8. Taylor expanded in l around 0 6.0%

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

    \[\leadsto \cos M \]

Reproduce

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