Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 96.8%
Time: 19.6s
Alternatives: 11
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 11 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.3% accurate, 1.0× speedup?

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

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

Alternative 1: 96.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{\left(\left|n - m\right| - \ell\right) - {\left(\frac{n + m}{2} - M\right)}^{2}} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (* (cos M) (exp (- (- (fabs (- n m)) l) (pow (- (/ (+ n m) 2.0) 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) / 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((n - m)) - l) - ((((n + m) / 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((n - m)) - l) - Math.pow((((n + m) / 2.0) - 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) / 2.0) - 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) / 2.0) - M) ^ 2.0))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp(((abs((n - m)) - l) - ((((n + m) / 2.0) - 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] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

Alternative 2: 67.7% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(n - m\right) - \left(M \cdot M + \ell\right)} \cdot \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right)\\ t_1 := \cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\ \mathbf{if}\;n \leq 1.9 \cdot 10^{-208}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;n \leq 2 \cdot 10^{-126}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;n \leq 4.9 \cdot 10^{-89}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;n \leq 185:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0
         (* (exp (- (- n m) (+ (* M M) l))) (cos (- (* (+ n m) (* 0.5 K)) M))))
        (t_1 (* (cos M) (exp (* -0.25 (* m m))))))
   (if (<= n 1.9e-208)
     t_1
     (if (<= n 2e-126)
       t_0
       (if (<= n 4.9e-89)
         t_1
         (if (<= n 185.0) t_0 (exp (* -0.25 (* n n)))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp(((n - m) - ((M * M) + l))) * cos((((n + m) * (0.5 * K)) - M));
	double t_1 = cos(M) * exp((-0.25 * (m * m)));
	double tmp;
	if (n <= 1.9e-208) {
		tmp = t_1;
	} else if (n <= 2e-126) {
		tmp = t_0;
	} else if (n <= 4.9e-89) {
		tmp = t_1;
	} else if (n <= 185.0) {
		tmp = t_0;
	} else {
		tmp = exp((-0.25 * (n * n)));
	}
	return tmp;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(((n - m) - ((m_1 * m_1) + l))) * cos((((n + m) * (0.5d0 * k)) - m_1))
    t_1 = cos(m_1) * exp(((-0.25d0) * (m * m)))
    if (n <= 1.9d-208) then
        tmp = t_1
    else if (n <= 2d-126) then
        tmp = t_0
    else if (n <= 4.9d-89) then
        tmp = t_1
    else if (n <= 185.0d0) then
        tmp = t_0
    else
        tmp = exp(((-0.25d0) * (n * n)))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp(((n - m) - ((M * M) + l))) * Math.cos((((n + m) * (0.5 * K)) - M));
	double t_1 = Math.cos(M) * Math.exp((-0.25 * (m * m)));
	double tmp;
	if (n <= 1.9e-208) {
		tmp = t_1;
	} else if (n <= 2e-126) {
		tmp = t_0;
	} else if (n <= 4.9e-89) {
		tmp = t_1;
	} else if (n <= 185.0) {
		tmp = t_0;
	} else {
		tmp = Math.exp((-0.25 * (n * n)));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp(((n - m) - ((M * M) + l))) * math.cos((((n + m) * (0.5 * K)) - M))
	t_1 = math.cos(M) * math.exp((-0.25 * (m * m)))
	tmp = 0
	if n <= 1.9e-208:
		tmp = t_1
	elif n <= 2e-126:
		tmp = t_0
	elif n <= 4.9e-89:
		tmp = t_1
	elif n <= 185.0:
		tmp = t_0
	else:
		tmp = math.exp((-0.25 * (n * n)))
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(exp(Float64(Float64(n - m) - Float64(Float64(M * M) + l))) * cos(Float64(Float64(Float64(n + m) * Float64(0.5 * K)) - M)))
	t_1 = Float64(cos(M) * exp(Float64(-0.25 * Float64(m * m))))
	tmp = 0.0
	if (n <= 1.9e-208)
		tmp = t_1;
	elseif (n <= 2e-126)
		tmp = t_0;
	elseif (n <= 4.9e-89)
		tmp = t_1;
	elseif (n <= 185.0)
		tmp = t_0;
	else
		tmp = exp(Float64(-0.25 * Float64(n * n)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp(((n - m) - ((M * M) + l))) * cos((((n + m) * (0.5 * K)) - M));
	t_1 = cos(M) * exp((-0.25 * (m * m)));
	tmp = 0.0;
	if (n <= 1.9e-208)
		tmp = t_1;
	elseif (n <= 2e-126)
		tmp = t_0;
	elseif (n <= 4.9e-89)
		tmp = t_1;
	elseif (n <= 185.0)
		tmp = t_0;
	else
		tmp = exp((-0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Exp[N[(N[(n - m), $MachinePrecision] - N[(N[(M * M), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(N[(n + m), $MachinePrecision] * N[(0.5 * K), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(-0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, 1.9e-208], t$95$1, If[LessEqual[n, 2e-126], t$95$0, If[LessEqual[n, 4.9e-89], t$95$1, If[LessEqual[n, 185.0], t$95$0, N[Exp[N[(-0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\left(n - m\right) - \left(M \cdot M + \ell\right)} \cdot \cos \left(\left(n + m\right) \cdot \left(0.5 \cdot K\right) - M\right)\\
t_1 := \cos M \cdot e^{-0.25 \cdot \left(m \cdot m\right)}\\
\mathbf{if}\;n \leq 1.9 \cdot 10^{-208}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;n \leq 2 \cdot 10^{-126}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;n \leq 4.9 \cdot 10^{-89}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;n \leq 185:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < 1.90000000000000006e-208 or 1.9999999999999999e-126 < n < 4.9e-89

    1. Initial program 76.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. Simplified76.0%

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

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

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

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

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

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

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

    if 1.90000000000000006e-208 < n < 1.9999999999999999e-126 or 4.9e-89 < n < 185

    1. Initial program 91.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. Simplified91.2%

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

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

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

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

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

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

    if 185 < 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. Simplified68.5%

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

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

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

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

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

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

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

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

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

Alternative 3: 90.2% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
t_0 := M - \left(n + m\right) \cdot 0.5\\
\mathbf{if}\;n \leq 2 \cdot 10^{+27}:\\
\;\;\;\;e^{\left(n - m\right) - \left(\ell + t\_0 \cdot t\_0\right)} \cdot \cos \left(0.5 \cdot \left(n \cdot K\right) - M\right)\\

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


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

    1. Initial program 78.4%

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

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

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

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

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

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

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

    if 2e27 < n

    1. Initial program 68.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. Simplified68.7%

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

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

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

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

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

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

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

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

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

Alternative 4: 77.9% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-0.25 \cdot \left(n \cdot n\right)}\\ t_1 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -1.65 \cdot 10^{-9}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;M \leq -8.5 \cdot 10^{-209}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 2.4 \cdot 10^{-222}:\\ \;\;\;\;e^{-\ell} \cdot \left(M \cdot \left(M \cdot -0.5\right)\right)\\ \mathbf{elif}\;M \leq 5000000000000:\\ \;\;\;\;t\_0 \cdot \left(1 + \left(M \cdot M\right) \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* -0.25 (* n n)))) (t_1 (* (cos M) (exp (* M (- M))))))
   (if (<= M -1.65e-9)
     t_1
     (if (<= M -8.5e-209)
       t_0
       (if (<= M 2.4e-222)
         (* (exp (- l)) (* M (* M -0.5)))
         (if (<= M 5000000000000.0) (* t_0 (+ 1.0 (* (* M M) -0.5))) t_1))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((-0.25 * (n * n)));
	double t_1 = cos(M) * exp((M * -M));
	double tmp;
	if (M <= -1.65e-9) {
		tmp = t_1;
	} else if (M <= -8.5e-209) {
		tmp = t_0;
	} else if (M <= 2.4e-222) {
		tmp = exp(-l) * (M * (M * -0.5));
	} else if (M <= 5000000000000.0) {
		tmp = t_0 * (1.0 + ((M * M) * -0.5));
	} 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 = exp(((-0.25d0) * (n * n)))
    t_1 = cos(m_1) * exp((m_1 * -m_1))
    if (m_1 <= (-1.65d-9)) then
        tmp = t_1
    else if (m_1 <= (-8.5d-209)) then
        tmp = t_0
    else if (m_1 <= 2.4d-222) then
        tmp = exp(-l) * (m_1 * (m_1 * (-0.5d0)))
    else if (m_1 <= 5000000000000.0d0) then
        tmp = t_0 * (1.0d0 + ((m_1 * m_1) * (-0.5d0)))
    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.exp((-0.25 * (n * n)));
	double t_1 = Math.cos(M) * Math.exp((M * -M));
	double tmp;
	if (M <= -1.65e-9) {
		tmp = t_1;
	} else if (M <= -8.5e-209) {
		tmp = t_0;
	} else if (M <= 2.4e-222) {
		tmp = Math.exp(-l) * (M * (M * -0.5));
	} else if (M <= 5000000000000.0) {
		tmp = t_0 * (1.0 + ((M * M) * -0.5));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((-0.25 * (n * n)))
	t_1 = math.cos(M) * math.exp((M * -M))
	tmp = 0
	if M <= -1.65e-9:
		tmp = t_1
	elif M <= -8.5e-209:
		tmp = t_0
	elif M <= 2.4e-222:
		tmp = math.exp(-l) * (M * (M * -0.5))
	elif M <= 5000000000000.0:
		tmp = t_0 * (1.0 + ((M * M) * -0.5))
	else:
		tmp = t_1
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(-0.25 * Float64(n * n)))
	t_1 = Float64(cos(M) * exp(Float64(M * Float64(-M))))
	tmp = 0.0
	if (M <= -1.65e-9)
		tmp = t_1;
	elseif (M <= -8.5e-209)
		tmp = t_0;
	elseif (M <= 2.4e-222)
		tmp = Float64(exp(Float64(-l)) * Float64(M * Float64(M * -0.5)));
	elseif (M <= 5000000000000.0)
		tmp = Float64(t_0 * Float64(1.0 + Float64(Float64(M * M) * -0.5)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp((-0.25 * (n * n)));
	t_1 = cos(M) * exp((M * -M));
	tmp = 0.0;
	if (M <= -1.65e-9)
		tmp = t_1;
	elseif (M <= -8.5e-209)
		tmp = t_0;
	elseif (M <= 2.4e-222)
		tmp = exp(-l) * (M * (M * -0.5));
	elseif (M <= 5000000000000.0)
		tmp = t_0 * (1.0 + ((M * M) * -0.5));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(-0.25 * N[(n * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(M * (-M)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -1.65e-9], t$95$1, If[LessEqual[M, -8.5e-209], t$95$0, If[LessEqual[M, 2.4e-222], N[(N[Exp[(-l)], $MachinePrecision] * N[(M * N[(M * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[M, 5000000000000.0], N[(t$95$0 * N[(1.0 + N[(N[(M * M), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-0.25 \cdot \left(n \cdot n\right)}\\
t_1 := \cos M \cdot e^{M \cdot \left(-M\right)}\\
\mathbf{if}\;M \leq -1.65 \cdot 10^{-9}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;M \leq -8.5 \cdot 10^{-209}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;M \leq 5000000000000:\\
\;\;\;\;t\_0 \cdot \left(1 + \left(M \cdot M\right) \cdot -0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if M < -1.65000000000000009e-9 or 5e12 < M

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

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

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

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

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

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

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

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

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

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

    if -1.65000000000000009e-9 < M < -8.5e-209

    1. Initial program 67.1%

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

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

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

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

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

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

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

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

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

    if -8.5e-209 < M < 2.39999999999999993e-222

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(1 + -0.5 \cdot {M}^{2}\right)} \cdot e^{-\ell} \]
      4. *-commutative35.6%

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

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

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

      \[\leadsto \color{blue}{-0.5 \cdot \left({M}^{2} \cdot e^{-\ell}\right)} \]
    14. Step-by-step derivation
      1. unpow282.2%

        \[\leadsto -0.5 \cdot \left(\color{blue}{\left(M \cdot M\right)} \cdot e^{-\ell}\right) \]
      2. associate-*r*82.2%

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

        \[\leadsto \color{blue}{\left(\left(M \cdot M\right) \cdot -0.5\right)} \cdot e^{-\ell} \]
      4. associate-*r*82.2%

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

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

    if 2.39999999999999993e-222 < M < 5e12

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 + -0.5 \cdot {M}^{2}\right)} \cdot e^{-0.25 \cdot \left(n \cdot n\right)} \]
    11. Step-by-step derivation
      1. unpow258.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -1.65 \cdot 10^{-9}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;M \leq -8.5 \cdot 10^{-209}:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \mathbf{elif}\;M \leq 2.4 \cdot 10^{-222}:\\ \;\;\;\;e^{-\ell} \cdot \left(M \cdot \left(M \cdot -0.5\right)\right)\\ \mathbf{elif}\;M \leq 5000000000000:\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)} \cdot \left(1 + \left(M \cdot M\right) \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 64.7% accurate, 1.9× speedup?

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

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

\mathbf{elif}\;n \leq 8.5 \cdot 10^{-74}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if n < 9.99999999999999925e-208

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

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

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

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

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

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

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

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

    if 9.99999999999999925e-208 < n < 8.50000000000000052e-74

    1. Initial program 90.1%

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

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

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

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

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

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

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

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

    if 8.50000000000000052e-74 < n < 54

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

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

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

    if 54 < n

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

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

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

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

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

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

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

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

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

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

Alternative 6: 68.9% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.22 \cdot 10^{-28} \lor \neg \left(n \leq 185\right):\\
\;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -1.22e-28 or 185 < n

    1. Initial program 69.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. Simplified69.4%

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

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

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

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

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

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

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

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

    if -1.22e-28 < n < 185

    1. Initial program 84.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. Simplified84.6%

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

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

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

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

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

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

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

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

Alternative 7: 68.6% accurate, 3.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.22 \cdot 10^{-28} \lor \neg \left(n \leq 185\right):\\
\;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < -1.22e-28 or 185 < n

    1. Initial program 69.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. Simplified69.4%

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

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

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

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

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

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

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

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

    if -1.22e-28 < n < 185

    1. Initial program 84.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. Simplified84.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -1.22 \cdot 10^{-28} \lor \neg \left(n \leq 185\right):\\ \;\;\;\;e^{-0.25 \cdot \left(n \cdot n\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 37.8% accurate, 3.8× speedup?

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

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

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


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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(m \cdot \left(e^{-\ell} \cdot \sin \left(-M\right)\right)\right)} \]
      2. *-commutative20.1%

        \[\leadsto \color{blue}{\left(K \cdot -0.5\right)} \cdot \left(m \cdot \left(e^{-\ell} \cdot \sin \left(-M\right)\right)\right) \]
      3. associate-*r*20.1%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \color{blue}{\left(\left(m \cdot e^{-\ell}\right) \cdot \sin \left(-M\right)\right)} \]
      4. rec-exp20.1%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(\left(m \cdot \color{blue}{\frac{1}{e^{\ell}}}\right) \cdot \sin \left(-M\right)\right) \]
      5. associate-*r/20.1%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(\color{blue}{\frac{m \cdot 1}{e^{\ell}}} \cdot \sin \left(-M\right)\right) \]
      6. metadata-eval20.1%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(\frac{m \cdot \color{blue}{\left(--1\right)}}{e^{\ell}} \cdot \sin \left(-M\right)\right) \]
      7. distribute-rgt-neg-in20.1%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(\frac{\color{blue}{-m \cdot -1}}{e^{\ell}} \cdot \sin \left(-M\right)\right) \]
      8. *-commutative20.1%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(\frac{-\color{blue}{-1 \cdot m}}{e^{\ell}} \cdot \sin \left(-M\right)\right) \]
      9. mul-1-neg20.1%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(\frac{-\color{blue}{\left(-m\right)}}{e^{\ell}} \cdot \sin \left(-M\right)\right) \]
      10. remove-double-neg20.1%

        \[\leadsto \left(K \cdot -0.5\right) \cdot \left(\frac{\color{blue}{m}}{e^{\ell}} \cdot \sin \left(-M\right)\right) \]
    10. Simplified20.1%

      \[\leadsto \color{blue}{\left(K \cdot -0.5\right) \cdot \left(\frac{m}{e^{\ell}} \cdot \sin \left(-M\right)\right)} \]
    11. Taylor expanded in l around 0 21.7%

      \[\leadsto \color{blue}{-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
    12. Step-by-step derivation
      1. associate-*r*21.7%

        \[\leadsto \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(-M\right)\right)} \]
      2. *-commutative21.7%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \color{blue}{\left(\sin \left(-M\right) \cdot m\right)} \]
      3. remove-double-neg21.7%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \color{blue}{\left(-\left(-m\right)\right)}\right) \]
      4. distribute-rgt-neg-out21.7%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \color{blue}{\left(-\sin \left(-M\right) \cdot \left(-m\right)\right)} \]
      5. distribute-rgt-neg-in21.7%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(-\color{blue}{\left(-\sin \left(-M\right) \cdot m\right)}\right) \]
      6. *-commutative21.7%

        \[\leadsto \left(-0.5 \cdot K\right) \cdot \left(-\left(-\color{blue}{m \cdot \sin \left(-M\right)}\right)\right) \]
      7. distribute-rgt-neg-out21.7%

        \[\leadsto \color{blue}{-\left(-0.5 \cdot K\right) \cdot \left(-m \cdot \sin \left(-M\right)\right)} \]
      8. distribute-rgt-neg-in21.7%

        \[\leadsto -\color{blue}{\left(-\left(-0.5 \cdot K\right) \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
      9. associate-*r*21.7%

        \[\leadsto -\left(-\color{blue}{-0.5 \cdot \left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)}\right) \]
      10. distribute-lft-neg-in21.7%

        \[\leadsto -\color{blue}{\left(--0.5\right) \cdot \left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
      11. metadata-eval21.7%

        \[\leadsto -\color{blue}{0.5} \cdot \left(K \cdot \left(m \cdot \sin \left(-M\right)\right)\right) \]
      12. distribute-rgt-neg-out21.7%

        \[\leadsto \color{blue}{0.5 \cdot \left(-K \cdot \left(m \cdot \sin \left(-M\right)\right)\right)} \]
      13. distribute-rgt-neg-in21.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(K \cdot \left(-m \cdot \sin \left(-M\right)\right)\right)} \]
      14. sin-neg21.7%

        \[\leadsto 0.5 \cdot \left(K \cdot \left(-m \cdot \color{blue}{\left(-\sin M\right)}\right)\right) \]
      15. distribute-rgt-neg-in21.7%

        \[\leadsto 0.5 \cdot \left(K \cdot \left(-\color{blue}{\left(-m \cdot \sin M\right)}\right)\right) \]
      16. remove-double-neg21.7%

        \[\leadsto 0.5 \cdot \left(K \cdot \color{blue}{\left(m \cdot \sin M\right)}\right) \]
    13. Simplified21.7%

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

    if 1.02000000000000002e-32 < l

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

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

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

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

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

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

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

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

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

Alternative 9: 35.5% 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.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. Simplified75.9%

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

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

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

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

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

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

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

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

Alternative 10: 7.2% 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.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. Simplified75.9%

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

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

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

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

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

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

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

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

Alternative 11: 7.2% accurate, 425.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (K m n M l) :precision binary64 1.0)
double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
real(8) function code(k, m, n, m_1, l)
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8), intent (in) :: n
    real(8), intent (in) :: m_1
    real(8), intent (in) :: l
    code = 1.0d0
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
def code(K, m, n, M, l):
	return 1.0
function code(K, m, n, M, l)
	return 1.0
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0;
end
code[K_, m_, n_, M_, l_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 75.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. Simplified75.9%

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

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

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

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

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

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

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

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

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

Reproduce

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