Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.6% → 96.6%
Time: 15.5s
Alternatives: 11
Speedup: 1.3×

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: 75.6% 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.6% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{m + n}{2} - M\\ \frac{\cos M}{e^{\left(t\_0 \cdot t\_0 + \ell\right) - \left|m - n\right|}} \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (/ (+ m n) 2.0) M)))
   (/ (cos M) (exp (- (+ (* t_0 t_0) l) (fabs (- m n)))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = ((m + n) / 2.0) - M;
	return cos(M) / exp((((t_0 * t_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
    real(8) :: t_0
    t_0 = ((m + n) / 2.0d0) - m_1
    code = cos(m_1) / exp((((t_0 * t_0) + l) - abs((m - n))))
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = ((m + n) / 2.0) - M;
	return Math.cos(M) / Math.exp((((t_0 * t_0) + l) - Math.abs((m - n))));
}
def code(K, m, n, M, l):
	t_0 = ((m + n) / 2.0) - M
	return math.cos(M) / math.exp((((t_0 * t_0) + l) - math.fabs((m - n))))
function code(K, m, n, M, l)
	t_0 = Float64(Float64(Float64(m + n) / 2.0) - M)
	return Float64(cos(M) / exp(Float64(Float64(Float64(t_0 * t_0) + l) - abs(Float64(m - n)))))
end
function tmp = code(K, m, n, M, l)
	t_0 = ((m + n) / 2.0) - M;
	tmp = cos(M) / exp((((t_0 * t_0) + l) - abs((m - n))));
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]}, N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] + l), $MachinePrecision] - N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{m + n}{2} - M\\
\frac{\cos M}{e^{\left(t\_0 \cdot t\_0 + \ell\right) - \left|m - n\right|}}
\end{array}
\end{array}
Derivation
  1. Initial program 73.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. Step-by-step derivation
    1. neg-sub0N/A

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. associate--l-N/A

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
    3. exp-diffN/A

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

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

      \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
    6. *-rgt-identityN/A

      \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
    7. /-lowering-/.f64N/A

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

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

    \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
  6. Step-by-step derivation
    1. cos-negN/A

      \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    2. cos-lowering-cos.f6494.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
  7. Simplified94.6%

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

Alternative 2: 66.5% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 3.5 \cdot 10^{-198}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{elif}\;n \leq 53:\\ \;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 3.5e-198)
   (/ (cos M) (exp (* 0.25 (* m m))))
   (if (<= n 53.0)
     (*
      (cos (- (/ (* (+ m n) K) 2.0) M))
      (exp (- (- (fabs (- m n)) l) (* M M))))
     (/ (cos M) (exp (* 0.25 (* n n)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 3.5e-198) {
		tmp = cos(M) / exp((0.25 * (m * m)));
	} else if (n <= 53.0) {
		tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((fabs((m - n)) - l) - (M * 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 <= 3.5d-198) then
        tmp = cos(m_1) / exp((0.25d0 * (m * m)))
    else if (n <= 53.0d0) then
        tmp = cos(((((m + n) * k) / 2.0d0) - m_1)) * exp(((abs((m - n)) - l) - (m_1 * 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 <= 3.5e-198) {
		tmp = Math.cos(M) / Math.exp((0.25 * (m * m)));
	} else if (n <= 53.0) {
		tmp = Math.cos(((((m + n) * K) / 2.0) - M)) * Math.exp(((Math.abs((m - n)) - l) - (M * 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 <= 3.5e-198:
		tmp = math.cos(M) / math.exp((0.25 * (m * m)))
	elif n <= 53.0:
		tmp = math.cos(((((m + n) * K) / 2.0) - M)) * math.exp(((math.fabs((m - n)) - l) - (M * 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 <= 3.5e-198)
		tmp = Float64(cos(M) / exp(Float64(0.25 * Float64(m * m))));
	elseif (n <= 53.0)
		tmp = Float64(cos(Float64(Float64(Float64(Float64(m + n) * K) / 2.0) - M)) * exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(M * 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 <= 3.5e-198)
		tmp = cos(M) / exp((0.25 * (m * m)));
	elseif (n <= 53.0)
		tmp = cos(((((m + n) * K) / 2.0) - M)) * exp(((abs((m - n)) - l) - (M * M)));
	else
		tmp = cos(M) / exp((0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 3.5e-198], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 53.0], N[(N[Cos[N[(N[(N[(N[(m + n), $MachinePrecision] * K), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(M * M), $MachinePrecision]), $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 3.5 \cdot 10^{-198}:\\
\;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(m \cdot m\right)}}\\

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

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


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

    1. Initial program 69.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6493.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified93.3%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
      3. *-lowering-*.f6453.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
    10. Simplified53.0%

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

    if 3.50000000000000025e-198 < n < 53

    1. Initial program 83.8%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{neg.f64}\left(\color{blue}{\left({M}^{2}\right)}\right), \mathsf{\_.f64}\left(\ell, \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right)\right) \]
    4. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{neg.f64}\left(\left(M \cdot M\right)\right), \mathsf{\_.f64}\left(\ell, \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right)\right) \]
      2. *-lowering-*.f6465.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{neg.f64}\left(\mathsf{*.f64}\left(M, M\right)\right), \mathsf{\_.f64}\left(\ell, \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right)\right) \]
    5. Simplified65.5%

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

    if 53 < n

    1. Initial program 75.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6498.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified98.6%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {n}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({n}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(n \cdot n\right)\right)\right)\right) \]
      3. *-lowering-*.f6495.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(n, n\right)\right)\right)\right) \]
    10. Simplified95.7%

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

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

Alternative 3: 66.5% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 69.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6493.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified93.3%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
      3. *-lowering-*.f6453.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
    10. Simplified53.0%

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

    if 1.59999999999999997e-198 < n < 53

    1. Initial program 83.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right), \color{blue}{\left(e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}\right)}\right) \]
    3. Simplified83.7%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\color{blue}{\left({M}^{2}\right)}, \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\left(M \cdot M\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
      2. *-lowering-*.f6465.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(M, M\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    7. Simplified65.4%

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

    if 53 < n

    1. Initial program 75.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6498.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified98.6%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {n}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({n}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(n \cdot n\right)\right)\right)\right) \]
      3. *-lowering-*.f6495.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(n, n\right)\right)\right)\right) \]
    10. Simplified95.7%

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

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

Alternative 4: 64.0% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 2.25 \cdot 10^{-197}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{elif}\;n \leq 5.1 \cdot 10^{-155}:\\ \;\;\;\;\cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot e^{0 - \ell}\\ \mathbf{elif}\;n \leq 53:\\ \;\;\;\;\frac{\cos \left(\frac{K}{\frac{2}{m + n}} - M\right)}{e^{M \cdot M}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 2.25e-197)
   (/ (cos M) (exp (* 0.25 (* m m))))
   (if (<= n 5.1e-155)
     (* (cos (* 0.5 (* n K))) (exp (- 0.0 l)))
     (if (<= n 53.0)
       (/ (cos (- (/ K (/ 2.0 (+ m n))) M)) (exp (* M 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.25e-197) {
		tmp = cos(M) / exp((0.25 * (m * m)));
	} else if (n <= 5.1e-155) {
		tmp = cos((0.5 * (n * K))) * exp((0.0 - l));
	} else if (n <= 53.0) {
		tmp = cos(((K / (2.0 / (m + n))) - M)) / exp((M * 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.25d-197) then
        tmp = cos(m_1) / exp((0.25d0 * (m * m)))
    else if (n <= 5.1d-155) then
        tmp = cos((0.5d0 * (n * k))) * exp((0.0d0 - l))
    else if (n <= 53.0d0) then
        tmp = cos(((k / (2.0d0 / (m + n))) - m_1)) / exp((m_1 * 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.25e-197) {
		tmp = Math.cos(M) / Math.exp((0.25 * (m * m)));
	} else if (n <= 5.1e-155) {
		tmp = Math.cos((0.5 * (n * K))) * Math.exp((0.0 - l));
	} else if (n <= 53.0) {
		tmp = Math.cos(((K / (2.0 / (m + n))) - M)) / Math.exp((M * 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.25e-197:
		tmp = math.cos(M) / math.exp((0.25 * (m * m)))
	elif n <= 5.1e-155:
		tmp = math.cos((0.5 * (n * K))) * math.exp((0.0 - l))
	elif n <= 53.0:
		tmp = math.cos(((K / (2.0 / (m + n))) - M)) / math.exp((M * 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.25e-197)
		tmp = Float64(cos(M) / exp(Float64(0.25 * Float64(m * m))));
	elseif (n <= 5.1e-155)
		tmp = Float64(cos(Float64(0.5 * Float64(n * K))) * exp(Float64(0.0 - l)));
	elseif (n <= 53.0)
		tmp = Float64(cos(Float64(Float64(K / Float64(2.0 / Float64(m + n))) - M)) / exp(Float64(M * 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.25e-197)
		tmp = cos(M) / exp((0.25 * (m * m)));
	elseif (n <= 5.1e-155)
		tmp = cos((0.5 * (n * K))) * exp((0.0 - l));
	elseif (n <= 53.0)
		tmp = cos(((K / (2.0 / (m + n))) - M)) / exp((M * 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.25e-197], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 5.1e-155], N[(N[Cos[N[(0.5 * N[(n * K), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(0.0 - l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 53.0], N[(N[Cos[N[(N[(K / N[(2.0 / N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] / N[Exp[N[(M * 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.25 \cdot 10^{-197}:\\
\;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(m \cdot m\right)}}\\

\mathbf{elif}\;n \leq 5.1 \cdot 10^{-155}:\\
\;\;\;\;\cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot e^{0 - \ell}\\

\mathbf{elif}\;n \leq 53:\\
\;\;\;\;\frac{\cos \left(\frac{K}{\frac{2}{m + n}} - M\right)}{e^{M \cdot M}}\\

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


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

    1. Initial program 69.2%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6493.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified93.3%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
      3. *-lowering-*.f6453.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
    10. Simplified53.0%

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

    if 2.25e-197 < n < 5.0999999999999996e-155

    1. Initial program 82.0%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\color{blue}{\left(-1 \cdot \ell\right)}\right)\right) \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\left(\mathsf{neg}\left(\ell\right)\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\left(0 - \ell\right)\right)\right) \]
      3. --lowering--.f6437.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \ell\right)\right)\right) \]
    5. Simplified37.5%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot n\right)\right)}\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \ell\right)\right)\right) \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(K \cdot n\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\color{blue}{0}, \ell\right)\right)\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(n \cdot K\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \ell\right)\right)\right) \]
      3. *-lowering-*.f6440.4%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(n, K\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \ell\right)\right)\right) \]
    8. Simplified40.4%

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

    if 5.0999999999999996e-155 < n < 53

    1. Initial program 84.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\color{blue}{\left(-1 \cdot {M}^{2}\right)}\right)\right) \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\left(\mathsf{neg}\left({M}^{2}\right)\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\left(0 - {M}^{2}\right)\right)\right) \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \left({M}^{2}\right)\right)\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \left(M \cdot M\right)\right)\right)\right) \]
      5. *-lowering-*.f6448.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(M, M\right)\right)\right)\right) \]
    5. Simplified48.1%

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{0 - M \cdot M}} \]
    6. Step-by-step derivation
      1. exp-diffN/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \frac{e^{0}}{\color{blue}{e^{M \cdot M}}} \]
      2. 1-expN/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \frac{1}{e^{\color{blue}{M \cdot M}}} \]
      3. un-div-invN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{\color{blue}{e^{M \cdot M}}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right), \color{blue}{\left(e^{M \cdot M}\right)}\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\left(\frac{K \cdot \left(m + n\right)}{2} - M\right)\right), \left(e^{\color{blue}{M \cdot M}}\right)\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\left(\frac{K \cdot \left(m + n\right)}{2}\right), M\right)\right), \left(e^{\color{blue}{M} \cdot M}\right)\right) \]
      7. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\left(K \cdot \frac{m + n}{2}\right), M\right)\right), \left(e^{M \cdot M}\right)\right) \]
      8. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\left(K \cdot \frac{1}{\frac{2}{m + n}}\right), M\right)\right), \left(e^{M \cdot M}\right)\right) \]
      9. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\left(\frac{K}{\frac{2}{m + n}}\right), M\right)\right), \left(e^{M \cdot M}\right)\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(K, \left(\frac{2}{m + n}\right)\right), M\right)\right), \left(e^{M \cdot M}\right)\right) \]
      11. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(K, \mathsf{/.f64}\left(2, \left(m + n\right)\right)\right), M\right)\right), \left(e^{M \cdot M}\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(K, \mathsf{/.f64}\left(2, \mathsf{+.f64}\left(m, n\right)\right)\right), M\right)\right), \left(e^{M \cdot M}\right)\right) \]
      13. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(K, \mathsf{/.f64}\left(2, \mathsf{+.f64}\left(m, n\right)\right)\right), M\right)\right), \mathsf{exp.f64}\left(\left(M \cdot M\right)\right)\right) \]
      14. *-lowering-*.f6448.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(K, \mathsf{/.f64}\left(2, \mathsf{+.f64}\left(m, n\right)\right)\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(M, M\right)\right)\right) \]
    7. Applied egg-rr48.3%

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

    if 53 < n

    1. Initial program 75.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6498.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified98.6%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {n}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({n}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(n \cdot n\right)\right)\right)\right) \]
      3. *-lowering-*.f6495.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(n, n\right)\right)\right)\right) \]
    10. Simplified95.7%

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

Alternative 5: 63.2% accurate, 1.9× speedup?

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

\mathbf{elif}\;n \leq 0.0082:\\
\;\;\;\;\cos \left(0.5 \cdot \left(n \cdot K\right)\right) \cdot e^{0 - \ell}\\

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


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

    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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6493.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified93.4%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
      3. *-lowering-*.f6453.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
    10. Simplified53.3%

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

    if 8.5000000000000005e-194 < n < 0.00820000000000000069

    1. Initial program 83.4%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\color{blue}{\left(-1 \cdot \ell\right)}\right)\right) \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\left(\mathsf{neg}\left(\ell\right)\right)\right)\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\left(0 - \ell\right)\right)\right) \]
      3. --lowering--.f6448.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \ell\right)\right)\right) \]
    5. Simplified48.6%

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot n\right)\right)}\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \ell\right)\right)\right) \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(K \cdot n\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\color{blue}{0}, \ell\right)\right)\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(n \cdot K\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \ell\right)\right)\right) \]
      3. *-lowering-*.f6453.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(n, K\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \ell\right)\right)\right) \]
    8. Simplified53.1%

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

    if 0.00820000000000000069 < n

    1. Initial program 75.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6498.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified98.6%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {n}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({n}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(n \cdot n\right)\right)\right)\right) \]
      3. *-lowering-*.f6495.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(n, n\right)\right)\right)\right) \]
    10. Simplified95.7%

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

Alternative 6: 65.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 5.3 \cdot 10^{-154}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(m \cdot m\right)}}\\ \mathbf{elif}\;n \leq 53:\\ \;\;\;\;\frac{\cos M}{e^{M \cdot M}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(n \cdot n\right)}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 5.3e-154)
   (/ (cos M) (exp (* 0.25 (* m m))))
   (if (<= n 53.0)
     (/ (cos M) (exp (* M M)))
     (/ (cos M) (exp (* 0.25 (* n n)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 5.3e-154) {
		tmp = cos(M) / exp((0.25 * (m * m)));
	} else if (n <= 53.0) {
		tmp = cos(M) / exp((M * 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 <= 5.3d-154) then
        tmp = cos(m_1) / exp((0.25d0 * (m * m)))
    else if (n <= 53.0d0) then
        tmp = cos(m_1) / exp((m_1 * 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 <= 5.3e-154) {
		tmp = Math.cos(M) / Math.exp((0.25 * (m * m)));
	} else if (n <= 53.0) {
		tmp = Math.cos(M) / Math.exp((M * 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 <= 5.3e-154:
		tmp = math.cos(M) / math.exp((0.25 * (m * m)))
	elif n <= 53.0:
		tmp = math.cos(M) / math.exp((M * 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 <= 5.3e-154)
		tmp = Float64(cos(M) / exp(Float64(0.25 * Float64(m * m))));
	elseif (n <= 53.0)
		tmp = Float64(cos(M) / exp(Float64(M * 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 <= 5.3e-154)
		tmp = cos(M) / exp((0.25 * (m * m)));
	elseif (n <= 53.0)
		tmp = cos(M) / exp((M * M));
	else
		tmp = cos(M) / exp((0.25 * (n * n)));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 5.3e-154], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(0.25 * N[(m * m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 53.0], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(M * 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 5.3 \cdot 10^{-154}:\\
\;\;\;\;\frac{\cos M}{e^{0.25 \cdot \left(m \cdot m\right)}}\\

\mathbf{elif}\;n \leq 53:\\
\;\;\;\;\frac{\cos M}{e^{M \cdot M}}\\

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


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

    1. Initial program 70.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6493.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified93.4%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
      3. *-lowering-*.f6453.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
    10. Simplified53.4%

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

    if 5.3000000000000002e-154 < n < 53

    1. Initial program 84.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6491.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified91.9%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left({M}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\left(M \cdot M\right)\right)\right) \]
      2. *-lowering-*.f6449.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(M, M\right)\right)\right) \]
    10. Simplified49.6%

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

    if 53 < n

    1. Initial program 75.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6498.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified98.6%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {n}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({n}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(n \cdot n\right)\right)\right)\right) \]
      3. *-lowering-*.f6495.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(n, n\right)\right)\right)\right) \]
    10. Simplified95.7%

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

Alternative 7: 63.0% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -1.25 \cdot 10^{-6}:\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

\mathbf{elif}\;m \leq -7 \cdot 10^{-249}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

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


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

    1. Initial program 60.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6498.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified98.6%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
    9. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
      3. *-lowering-*.f6491.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
    10. Simplified91.5%

      \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot \left(m \cdot m\right)}}} \]
    11. Taylor expanded in M around 0

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(1 + {M}^{2} \cdot \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)}, \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
    12. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left({M}^{2} \cdot \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)}\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left({M}^{2}\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \color{blue}{\mathsf{*.f64}\left(m, m\right)}\right)\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(M \cdot M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\color{blue}{m}, m\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\color{blue}{m}, m\right)\right)\right)\right) \]
      5. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, \color{blue}{m}\right)\right)\right)\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) + \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      7. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, \color{blue}{m}\right)\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\left({M}^{2}\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      9. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(M \cdot M\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      11. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \left(\frac{-1}{720} \cdot {M}^{2}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \left({M}^{2} \cdot \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left({M}^{2}\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      14. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left(M \cdot M\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      15. *-lowering-*.f6447.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
    13. Simplified47.9%

      \[\leadsto \frac{\color{blue}{1 + \left(M \cdot M\right) \cdot \left(\left(M \cdot M\right) \cdot \left(0.041666666666666664 + \left(M \cdot M\right) \cdot -0.001388888888888889\right) + -0.5\right)}}{e^{0.25 \cdot \left(m \cdot m\right)}} \]
    14. Taylor expanded in M around 0

      \[\leadsto \color{blue}{\frac{1}{e^{\frac{1}{4} \cdot {m}^{2}}}} \]
    15. Step-by-step derivation
      1. rec-expN/A

        \[\leadsto e^{\mathsf{neg}\left(\frac{1}{4} \cdot {m}^{2}\right)} \]
      2. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{exp.f64}\left(\left(\mathsf{neg}\left(\frac{1}{4} \cdot {m}^{2}\right)\right)\right) \]
      3. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{exp.f64}\left(\left(\left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot {m}^{2}\right)\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{exp.f64}\left(\left(\frac{-1}{4} \cdot {m}^{2}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \left({m}^{2}\right)\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \left(m \cdot m\right)\right)\right) \]
      7. *-lowering-*.f6491.5%

        \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right) \]
    16. Simplified91.5%

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

    if -1.2500000000000001e-6 < m < -7.00000000000000025e-249

    1. Initial program 80.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. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. associate--l-N/A

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
      3. exp-diffN/A

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

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

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
      7. /-lowering-/.f64N/A

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

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      2. cos-lowering-cos.f6495.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
    7. Simplified95.6%

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\ell}\right)\right) \]
    9. Step-by-step derivation
      1. Simplified56.0%

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

      if -7.00000000000000025e-249 < m

      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. Step-by-step derivation
        1. neg-sub0N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
        2. associate--l-N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
        3. exp-diffN/A

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

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

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
        6. *-rgt-identityN/A

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
        7. /-lowering-/.f64N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
      6. Step-by-step derivation
        1. cos-negN/A

          \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
        2. cos-lowering-cos.f6492.7%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      7. Simplified92.7%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left({M}^{2}\right)}\right)\right) \]
      9. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\left(M \cdot M\right)\right)\right) \]
        2. *-lowering-*.f6455.8%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(M, M\right)\right)\right) \]
      10. Simplified55.8%

        \[\leadsto \frac{\cos M}{e^{\color{blue}{M \cdot M}}} \]
    10. Recombined 3 regimes into one program.
    11. Final simplification63.5%

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

    Alternative 8: 69.0% accurate, 2.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{if}\;m \leq -0.00102:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;m \leq 8.5 \cdot 10^{-30}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (K m n M l)
     :precision binary64
     (let* ((t_0 (exp (* (* m m) -0.25))))
       (if (<= m -0.00102) t_0 (if (<= m 8.5e-30) (/ (cos M) (exp l)) t_0))))
    double code(double K, double m, double n, double M, double l) {
    	double t_0 = exp(((m * m) * -0.25));
    	double tmp;
    	if (m <= -0.00102) {
    		tmp = t_0;
    	} else if (m <= 8.5e-30) {
    		tmp = cos(M) / exp(l);
    	} else {
    		tmp = 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(((m * m) * (-0.25d0)))
        if (m <= (-0.00102d0)) then
            tmp = t_0
        else if (m <= 8.5d-30) then
            tmp = cos(m_1) / exp(l)
        else
            tmp = 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(((m * m) * -0.25));
    	double tmp;
    	if (m <= -0.00102) {
    		tmp = t_0;
    	} else if (m <= 8.5e-30) {
    		tmp = Math.cos(M) / Math.exp(l);
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(K, m, n, M, l):
    	t_0 = math.exp(((m * m) * -0.25))
    	tmp = 0
    	if m <= -0.00102:
    		tmp = t_0
    	elif m <= 8.5e-30:
    		tmp = math.cos(M) / math.exp(l)
    	else:
    		tmp = t_0
    	return tmp
    
    function code(K, m, n, M, l)
    	t_0 = exp(Float64(Float64(m * m) * -0.25))
    	tmp = 0.0
    	if (m <= -0.00102)
    		tmp = t_0;
    	elseif (m <= 8.5e-30)
    		tmp = Float64(cos(M) / exp(l));
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(K, m, n, M, l)
    	t_0 = exp(((m * m) * -0.25));
    	tmp = 0.0;
    	if (m <= -0.00102)
    		tmp = t_0;
    	elseif (m <= 8.5e-30)
    		tmp = cos(M) / exp(l);
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[(m * m), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[m, -0.00102], t$95$0, If[LessEqual[m, 8.5e-30], N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision], t$95$0]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := e^{\left(m \cdot m\right) \cdot -0.25}\\
    \mathbf{if}\;m \leq -0.00102:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;m \leq 8.5 \cdot 10^{-30}:\\
    \;\;\;\;\frac{\cos M}{e^{\ell}}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if m < -0.00102 or 8.49999999999999931e-30 < m

      1. Initial program 66.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. Step-by-step derivation
        1. neg-sub0N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
        2. associate--l-N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
        3. exp-diffN/A

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

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

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
        6. *-rgt-identityN/A

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
        7. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right), \color{blue}{\left(e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}\right)}\right) \]
      3. Simplified66.8%

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

        \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
      6. Step-by-step derivation
        1. cos-negN/A

          \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
        2. cos-lowering-cos.f6495.7%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      7. Simplified95.7%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
      9. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
        2. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
        3. *-lowering-*.f6488.2%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      10. Simplified88.2%

        \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot \left(m \cdot m\right)}}} \]
      11. Taylor expanded in M around 0

        \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(1 + {M}^{2} \cdot \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)}, \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      12. Step-by-step derivation
        1. +-lowering-+.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left({M}^{2} \cdot \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)}\right)\right) \]
        2. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left({M}^{2}\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \color{blue}{\mathsf{*.f64}\left(m, m\right)}\right)\right)\right) \]
        3. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(M \cdot M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\color{blue}{m}, m\right)\right)\right)\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\color{blue}{m}, m\right)\right)\right)\right) \]
        5. sub-negN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, \color{blue}{m}\right)\right)\right)\right) \]
        6. metadata-evalN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) + \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        7. +-lowering-+.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, \color{blue}{m}\right)\right)\right)\right) \]
        8. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\left({M}^{2}\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        9. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(M \cdot M\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        10. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        11. +-lowering-+.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \left(\frac{-1}{720} \cdot {M}^{2}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        12. *-commutativeN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \left({M}^{2} \cdot \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        13. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left({M}^{2}\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        14. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left(M \cdot M\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        15. *-lowering-*.f6446.3%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      13. Simplified46.3%

        \[\leadsto \frac{\color{blue}{1 + \left(M \cdot M\right) \cdot \left(\left(M \cdot M\right) \cdot \left(0.041666666666666664 + \left(M \cdot M\right) \cdot -0.001388888888888889\right) + -0.5\right)}}{e^{0.25 \cdot \left(m \cdot m\right)}} \]
      14. Taylor expanded in M around 0

        \[\leadsto \color{blue}{\frac{1}{e^{\frac{1}{4} \cdot {m}^{2}}}} \]
      15. Step-by-step derivation
        1. rec-expN/A

          \[\leadsto e^{\mathsf{neg}\left(\frac{1}{4} \cdot {m}^{2}\right)} \]
        2. exp-lowering-exp.f64N/A

          \[\leadsto \mathsf{exp.f64}\left(\left(\mathsf{neg}\left(\frac{1}{4} \cdot {m}^{2}\right)\right)\right) \]
        3. distribute-lft-neg-inN/A

          \[\leadsto \mathsf{exp.f64}\left(\left(\left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot {m}^{2}\right)\right) \]
        4. metadata-evalN/A

          \[\leadsto \mathsf{exp.f64}\left(\left(\frac{-1}{4} \cdot {m}^{2}\right)\right) \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \left({m}^{2}\right)\right)\right) \]
        6. unpow2N/A

          \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \left(m \cdot m\right)\right)\right) \]
        7. *-lowering-*.f6488.2%

          \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right) \]
      16. Simplified88.2%

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

      if -0.00102 < m < 8.49999999999999931e-30

      1. Initial program 79.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. neg-sub0N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
        2. associate--l-N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
        3. exp-diffN/A

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

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

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
        6. *-rgt-identityN/A

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
        7. /-lowering-/.f64N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
      6. Step-by-step derivation
        1. cos-negN/A

          \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
        2. cos-lowering-cos.f6493.4%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      7. Simplified93.4%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\ell}\right)\right) \]
      9. Step-by-step derivation
        1. Simplified40.6%

          \[\leadsto \frac{\cos M}{e^{\color{blue}{\ell}}} \]
      10. Recombined 2 regimes into one program.
      11. Final simplification64.6%

        \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -0.00102:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \mathbf{elif}\;m \leq 8.5 \cdot 10^{-30}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{else}:\\ \;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\ \end{array} \]
      12. Add Preprocessing

      Alternative 9: 54.4% accurate, 4.0× speedup?

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

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
        2. associate--l-N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
        3. exp-diffN/A

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

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

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
        6. *-rgt-identityN/A

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
        7. /-lowering-/.f64N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
      6. Step-by-step derivation
        1. cos-negN/A

          \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
        2. cos-lowering-cos.f6494.6%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      7. Simplified94.6%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
      9. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
        2. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
        3. *-lowering-*.f6448.8%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      10. Simplified48.8%

        \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot \left(m \cdot m\right)}}} \]
      11. Taylor expanded in M around 0

        \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(1 + {M}^{2} \cdot \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)}, \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      12. Step-by-step derivation
        1. +-lowering-+.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left({M}^{2} \cdot \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)}\right)\right) \]
        2. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left({M}^{2}\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \color{blue}{\mathsf{*.f64}\left(m, m\right)}\right)\right)\right) \]
        3. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(M \cdot M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\color{blue}{m}, m\right)\right)\right)\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(\color{blue}{m}, m\right)\right)\right)\right) \]
        5. sub-negN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, \color{blue}{m}\right)\right)\right)\right) \]
        6. metadata-evalN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right) + \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        7. +-lowering-+.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\left({M}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, \color{blue}{m}\right)\right)\right)\right) \]
        8. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\left({M}^{2}\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        9. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(M \cdot M\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        10. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {M}^{2}\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        11. +-lowering-+.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \left(\frac{-1}{720} \cdot {M}^{2}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        12. *-commutativeN/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \left({M}^{2} \cdot \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        13. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left({M}^{2}\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        14. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left(M \cdot M\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
        15. *-lowering-*.f6427.4%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(M, M\right), \frac{-1}{720}\right)\right)\right), \frac{-1}{2}\right)\right)\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      13. Simplified27.4%

        \[\leadsto \frac{\color{blue}{1 + \left(M \cdot M\right) \cdot \left(\left(M \cdot M\right) \cdot \left(0.041666666666666664 + \left(M \cdot M\right) \cdot -0.001388888888888889\right) + -0.5\right)}}{e^{0.25 \cdot \left(m \cdot m\right)}} \]
      14. Taylor expanded in M around 0

        \[\leadsto \color{blue}{\frac{1}{e^{\frac{1}{4} \cdot {m}^{2}}}} \]
      15. Step-by-step derivation
        1. rec-expN/A

          \[\leadsto e^{\mathsf{neg}\left(\frac{1}{4} \cdot {m}^{2}\right)} \]
        2. exp-lowering-exp.f64N/A

          \[\leadsto \mathsf{exp.f64}\left(\left(\mathsf{neg}\left(\frac{1}{4} \cdot {m}^{2}\right)\right)\right) \]
        3. distribute-lft-neg-inN/A

          \[\leadsto \mathsf{exp.f64}\left(\left(\left(\mathsf{neg}\left(\frac{1}{4}\right)\right) \cdot {m}^{2}\right)\right) \]
        4. metadata-evalN/A

          \[\leadsto \mathsf{exp.f64}\left(\left(\frac{-1}{4} \cdot {m}^{2}\right)\right) \]
        5. *-lowering-*.f64N/A

          \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \left({m}^{2}\right)\right)\right) \]
        6. unpow2N/A

          \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \left(m \cdot m\right)\right)\right) \]
        7. *-lowering-*.f6448.8%

          \[\leadsto \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{-1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right) \]
      16. Simplified48.8%

        \[\leadsto \color{blue}{e^{-0.25 \cdot \left(m \cdot m\right)}} \]
      17. Final simplification48.8%

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

      Alternative 10: 7.1% 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 73.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. Step-by-step derivation
        1. neg-sub0N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(0 - {\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
        2. associate--l-N/A

          \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{0 - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)\right)} \]
        3. exp-diffN/A

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

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

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot 1}{e^{{\left(\frac{m + n}{2} - M\right)}^{2} + \color{blue}{\left(\ell - \left|m - n\right|\right)}}} \]
        6. *-rgt-identityN/A

          \[\leadsto \frac{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right)}{e^{\color{blue}{{\left(\frac{m + n}{2} - M\right)}^{2} + \left(\ell - \left|m - n\right|\right)}}} \]
        7. /-lowering-/.f64N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(\color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)}, \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)\right)\right) \]
      6. Step-by-step derivation
        1. cos-negN/A

          \[\leadsto \mathsf{/.f64}\left(\cos M, \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
        2. cos-lowering-cos.f6494.6%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\mathsf{\_.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right), \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(m, n\right), 2\right), M\right)\right), \ell\right), \mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(m, n\right)\right)\right)}\right)\right) \]
      7. Simplified94.6%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\color{blue}{\left(\frac{1}{4} \cdot {m}^{2}\right)}\right)\right) \]
      9. Step-by-step derivation
        1. *-lowering-*.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left({m}^{2}\right)\right)\right)\right) \]
        2. unpow2N/A

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \left(m \cdot m\right)\right)\right)\right) \]
        3. *-lowering-*.f6448.8%

          \[\leadsto \mathsf{/.f64}\left(\mathsf{cos.f64}\left(M\right), \mathsf{exp.f64}\left(\mathsf{*.f64}\left(\frac{1}{4}, \mathsf{*.f64}\left(m, m\right)\right)\right)\right) \]
      10. Simplified48.8%

        \[\leadsto \frac{\cos M}{e^{\color{blue}{0.25 \cdot \left(m \cdot m\right)}}} \]
      11. Taylor expanded in m around 0

        \[\leadsto \color{blue}{\cos M} \]
      12. Step-by-step derivation
        1. cos-lowering-cos.f646.4%

          \[\leadsto \mathsf{cos.f64}\left(M\right) \]
      13. Simplified6.4%

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

      Alternative 11: 7.1% 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 73.3%

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\color{blue}{\left(-1 \cdot {M}^{2}\right)}\right)\right) \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\left(\mathsf{neg}\left({M}^{2}\right)\right)\right)\right) \]
        2. neg-sub0N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\left(0 - {M}^{2}\right)\right)\right) \]
        3. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \left({M}^{2}\right)\right)\right)\right) \]
        4. unpow2N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \left(M \cdot M\right)\right)\right)\right) \]
        5. *-lowering-*.f6439.6%

          \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(K, \mathsf{+.f64}\left(m, n\right)\right), 2\right), M\right)\right), \mathsf{exp.f64}\left(\mathsf{\_.f64}\left(0, \mathsf{*.f64}\left(M, M\right)\right)\right)\right) \]
      5. Simplified39.6%

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

        \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right)} \]
      7. Step-by-step derivation
        1. cos-lowering-cos.f64N/A

          \[\leadsto \mathsf{cos.f64}\left(\left(\frac{1}{2} \cdot \left(K \cdot \left(m + n\right)\right)\right)\right) \]
        2. *-lowering-*.f64N/A

          \[\leadsto \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(K \cdot \left(m + n\right)\right)\right)\right) \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\left(m + n\right) \cdot K\right)\right)\right) \]
        4. *-lowering-*.f64N/A

          \[\leadsto \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\left(m + n\right), K\right)\right)\right) \]
        5. +-lowering-+.f646.1%

          \[\leadsto \mathsf{cos.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(\mathsf{+.f64}\left(m, n\right), K\right)\right)\right) \]
      8. Simplified6.1%

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

        \[\leadsto \color{blue}{1} \]
      10. Step-by-step derivation
        1. Simplified6.4%

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

        Reproduce

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