Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.4% → 96.7%
Time: 14.7s
Alternatives: 10
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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

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

Alternative 1: 96.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.6% accurate, 1.3× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
    4. fabs-sqr52.1%

      \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
    5. add-sqr-sqrt96.0%

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

      \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right)}^{2}}\right)} - 1\right) \]
    7. fma-neg96.0%

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

      \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, \color{blue}{0.5}, -M\right)\right)}^{2}}\right)} - 1\right) \]
  8. Applied egg-rr96.0%

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

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

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

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

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

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

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

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

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

Alternative 3: 51.8% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 7.9 \cdot 10^{-171}:\\
\;\;\;\;\cos M \cdot e^{m}\\

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

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


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

    1. Initial program 78.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right)} \]
      3. add-sqr-sqrt65.5%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      4. fabs-sqr65.5%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      5. add-sqr-sqrt95.6%

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

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

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

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

      \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def95.6%

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

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

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

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

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

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

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

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

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

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

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

    if 7.8999999999999998e-171 < n < 35

    1. Initial program 79.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-1 \cdot \color{blue}{\left(M \cdot M\right)}} \]
      2. neg-mul-160.8%

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

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

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

    if 35 < n

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot -0.25} \]
      3. associate-*l*98.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 7.9 \cdot 10^{-171}:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{elif}\;n \leq 35:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 4: 74.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{\left(m - \left(n + \ell\right)\right) - M \cdot M} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (* (cos M) (exp (- (- m (+ n l)) (* M M)))))
double code(double K, double m, double n, double M, double l) {
	return cos(M) * exp(((m - (n + l)) - (M * 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) * exp(((m - (n + l)) - (m_1 * m_1)))
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M) * Math.exp(((m - (n + l)) - (M * M)));
}
def code(K, m, n, M, l):
	return math.cos(M) * math.exp(((m - (n + l)) - (M * M)))
function code(K, m, n, M, l)
	return Float64(cos(M) * exp(Float64(Float64(m - Float64(n + l)) - Float64(M * M))))
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M) * exp(((m - (n + l)) - (M * M)));
end
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(m - N[(n + l), $MachinePrecision]), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
    4. fabs-sqr52.1%

      \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
    5. add-sqr-sqrt96.0%

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

      \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right)}^{2}}\right)} - 1\right) \]
    7. fma-neg96.0%

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

      \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, \color{blue}{0.5}, -M\right)\right)}^{2}}\right)} - 1\right) \]
  8. Applied egg-rr96.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos M \cdot e^{\left(m - \left(n + \ell\right)\right) - \color{blue}{M \cdot M}} \]
  14. Final simplification70.6%

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

Alternative 5: 51.8% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 9.6 \cdot 10^{-175}:\\
\;\;\;\;\cos M \cdot e^{m}\\

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

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


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

    1. Initial program 78.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. *-commutative78.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      4. fabs-sqr65.3%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      5. add-sqr-sqrt95.6%

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

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

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

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

      \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def95.6%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(m - \left(n + \ell\right)\right) - \color{blue}{M \cdot M}} \]
    13. Simplified63.9%

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

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

    if 9.6e-175 < n < 35

    1. Initial program 80.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. *-commutative80.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-1 \cdot \color{blue}{\left(M \cdot M\right)}} \]
      2. neg-mul-161.9%

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

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

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

    if 35 < n

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right)} \]
      3. add-sqr-sqrt21.5%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      4. fabs-sqr21.5%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      5. add-sqr-sqrt100.0%

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right)}^{2}}\right)} - 1\right) \]
      7. fma-neg100.0%

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, \color{blue}{0.5}, -M\right)\right)}^{2}}\right)} - 1\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot n}} \]
    15. Step-by-step derivation
      1. mul-1-neg97.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{-n}} \]
    16. Simplified97.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 9.6 \cdot 10^{-175}:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{elif}\;n \leq 35:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-n}\\ \end{array} \]

Alternative 6: 51.5% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -7 \cdot 10^{-9}:\\
\;\;\;\;\cos M \cdot e^{m}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -6.9999999999999998e-9

    1. Initial program 70.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. *-commutative70.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right)} \]
      3. add-sqr-sqrt12.7%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      4. fabs-sqr12.7%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      5. add-sqr-sqrt100.0%

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right)}^{2}}\right)} - 1\right) \]
      7. fma-neg100.0%

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, \color{blue}{0.5}, -M\right)\right)}^{2}}\right)} - 1\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def100.0%

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

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

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

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

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

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

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

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

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

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

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

    if -6.9999999999999998e-9 < m

    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. *-commutative78.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -7 \cdot 10^{-9}:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]

Alternative 7: 48.2% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 35:\\
\;\;\;\;\cos M \cdot e^{m}\\

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


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

    1. Initial program 78.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. *-commutative78.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right)} \]
      3. add-sqr-sqrt62.4%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      4. fabs-sqr62.4%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      5. add-sqr-sqrt94.6%

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

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

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

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

      \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def95.0%

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

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

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

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

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

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

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

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

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

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

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

    if 35 < n

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right)} \]
      3. add-sqr-sqrt21.5%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      4. fabs-sqr21.5%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      5. add-sqr-sqrt100.0%

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right)}^{2}}\right)} - 1\right) \]
      7. fma-neg100.0%

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, \color{blue}{0.5}, -M\right)\right)}^{2}}\right)} - 1\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot n}} \]
    15. Step-by-step derivation
      1. mul-1-neg97.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{-n}} \]
    16. Simplified97.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 35:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-n}\\ \end{array} \]

Alternative 8: 50.6% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -1.85 \cdot 10^{-37}:\\
\;\;\;\;\cos M \cdot e^{m}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -1.85e-37

    1. Initial program 71.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right)} \]
      3. add-sqr-sqrt20.0%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left|\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      4. fabs-sqr20.0%

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\right)} - 1\right) \]
      5. add-sqr-sqrt100.0%

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right)}^{2}}\right)} - 1\right) \]
      7. fma-neg100.0%

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

        \[\leadsto \cos M \cdot \left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, \color{blue}{0.5}, -M\right)\right)}^{2}}\right)} - 1\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \cos M \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(e^{\left(\left(m - n\right) - \ell\right) - {\left(\mathsf{fma}\left(m + n, 0.5, -M\right)\right)}^{2}}\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def100.0%

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

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

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

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

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

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

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

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

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

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

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

    if -1.85e-37 < m

    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. *-commutative78.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -1.85 \cdot 10^{-37}:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 9: 34.1% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 76.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. *-commutative76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 7.0% 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.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. *-commutative76.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos M} \]
  11. Final simplification6.1%

    \[\leadsto \cos M \]

Reproduce

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