Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 96.9%
Time: 20.8s
Alternatives: 10
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 76.3% accurate, 1.0× speedup?

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

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

Alternative 1: 96.9% accurate, 1.0× speedup?

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

\\
\cos M \cdot e^{\left(\left|n - m\right| - \ell\right) - {\left(\left(n + m\right) \cdot 0.5 - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 76.5%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Step-by-step derivation
    1. associate-/l*76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 64.2% accurate, 1.3× speedup?

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

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

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

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


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

    1. Initial program 69.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. Step-by-step derivation
      1. associate-/l*69.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    12. Applied egg-rr97.2%

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

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

    if -54 < m < 1.25e-268

    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. associate-/l*83.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.25e-268 < m

    1. Initial program 76.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. associate-/l*77.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    10. Simplified60.0%

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

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

Alternative 3: 76.2% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{-{M}^{2}}\\
\mathbf{if}\;M \leq -1.05 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq -5.2 \cdot 10^{-63}:\\
\;\;\;\;\cos M \cdot e^{-\ell}\\

\mathbf{elif}\;M \leq 0.0018:\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if M < -1.05e14 or 0.0018 < M

    1. Initial program 79.5%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*80.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-{M}^{2}}} \]
    10. Simplified93.6%

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

    if -1.05e14 < M < -5.2000000000000003e-63

    1. Initial program 78.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. associate-/l*78.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.2000000000000003e-63 < M < 0.0018

    1. Initial program 73.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. associate-/l*73.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    12. Applied egg-rr60.8%

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

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

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

Alternative 4: 66.2% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;m \leq -5.5 \cdot 10^{-308}:\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\

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


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

    1. Initial program 69.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. Step-by-step derivation
      1. associate-/l*69.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    12. Applied egg-rr97.2%

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

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

    if -54 < m < -5.5e-308

    1. Initial program 86.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. associate-/l*86.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.5e-308 < m

    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. associate-/l*76.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
    10. Simplified57.8%

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

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

Alternative 5: 68.4% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -8.8 \cdot 10^{-7} \lor \neg \left(m \leq 8 \cdot 10^{-38}\right):\\
\;\;\;\;\cos M \cdot e^{\left(m \cdot m\right) \cdot -0.25}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -8.8000000000000004e-7 or 7.9999999999999997e-38 < m

    1. Initial program 71.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. associate-/l*72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    10. Simplified93.0%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    12. Applied egg-rr93.0%

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

    if -8.8000000000000004e-7 < m < 7.9999999999999997e-38

    1. Initial program 81.8%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*81.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 68.4% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -8.8 \cdot 10^{-7} \lor \neg \left(m \leq 8 \cdot 10^{-38}\right):\\
\;\;\;\;e^{\left(m \cdot m\right) \cdot -0.25}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -8.8000000000000004e-7 or 7.9999999999999997e-38 < m

    1. Initial program 71.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. associate-/l*72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    10. Simplified93.0%

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    12. Applied egg-rr93.0%

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

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

    if -8.8000000000000004e-7 < m < 7.9999999999999997e-38

    1. Initial program 81.8%

      \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
    2. Step-by-step derivation
      1. associate-/l*81.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 19.5% accurate, 4.0× speedup?

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

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

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Step-by-step derivation
    1. associate-/l*76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)} \]
  9. Step-by-step derivation
    1. fma-neg5.5%

      \[\leadsto \cos \color{blue}{\left(\mathsf{fma}\left(0.5, K \cdot n, -M\right)\right)} \]
    2. *-commutative5.5%

      \[\leadsto \cos \left(\mathsf{fma}\left(0.5, \color{blue}{n \cdot K}, -M\right)\right) \]
    3. fma-neg5.5%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(n \cdot K\right) - M\right)} \]
    4. associate-*r*5.5%

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

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

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

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

      \[\leadsto \cos M + -0.5 \cdot \left(K \cdot \left(n \cdot \color{blue}{\left(-\sin M\right)}\right)\right) \]
  13. Simplified5.5%

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

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

Alternative 8: 53.7% 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 76.5%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Step-by-step derivation
    1. associate-/l*76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  10. Simplified54.7%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
  12. Applied egg-rr54.7%

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

    \[\leadsto \color{blue}{1} \cdot e^{\left(m \cdot m\right) \cdot -0.25} \]
  14. Final simplification54.7%

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

Alternative 9: 6.8% 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 76.5%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Step-by-step derivation
    1. associate-/l*76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  10. Simplified54.7%

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

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

Alternative 10: 6.8% 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 76.5%

    \[\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  2. Step-by-step derivation
    1. associate-/l*76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
  10. Simplified54.7%

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

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

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

Reproduce

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