Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.9% → 96.7%
Time: 18.9s
Alternatives: 10
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 76.9% 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 81.4%

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

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

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

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

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

Alternative 2: 96.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{\left(\left(m - n\right) - \ell\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(Float64(m - 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[(N[(m - n), $MachinePrecision] - l), $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(\left(m - n\right) - \ell\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 88.2% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(m - n\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(m - n\right)}^{\left(\frac{1}{2}\right)}} - \ell\right) - {\left(0.5 \cdot n - M\right)}^{2}} \]
    13. sqr-pow89.2%

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

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

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

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

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

Alternative 4: 48.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{-n}\\ \mathbf{if}\;m \leq -54:\\ \;\;\;\;{\left(e^{m}\right)}^{\left(m \cdot -0.25\right)}\\ \mathbf{elif}\;m \leq -1.25 \cdot 10^{-134}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;m \leq -2.9 \cdot 10^{-178}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{elif}\;m \leq 2.6 \cdot 10^{-290} \lor \neg \left(m \leq 7.1 \cdot 10^{-227}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos M) (exp (- n)))))
   (if (<= m -54.0)
     (pow (exp m) (* m -0.25))
     (if (<= m -1.25e-134)
       t_0
       (if (<= m -2.9e-178)
         (/ (cos M) (exp l))
         (if (or (<= m 2.6e-290) (not (<= m 7.1e-227))) t_0 (exp (- l))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp(-n);
	double tmp;
	if (m <= -54.0) {
		tmp = pow(exp(m), (m * -0.25));
	} else if (m <= -1.25e-134) {
		tmp = t_0;
	} else if (m <= -2.9e-178) {
		tmp = cos(M) / exp(l);
	} else if ((m <= 2.6e-290) || !(m <= 7.1e-227)) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = cos(m_1) * exp(-n)
    if (m <= (-54.0d0)) then
        tmp = exp(m) ** (m * (-0.25d0))
    else if (m <= (-1.25d-134)) then
        tmp = t_0
    else if (m <= (-2.9d-178)) then
        tmp = cos(m_1) / exp(l)
    else if ((m <= 2.6d-290) .or. (.not. (m <= 7.1d-227))) then
        tmp = t_0
    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 t_0 = Math.cos(M) * Math.exp(-n);
	double tmp;
	if (m <= -54.0) {
		tmp = Math.pow(Math.exp(m), (m * -0.25));
	} else if (m <= -1.25e-134) {
		tmp = t_0;
	} else if (m <= -2.9e-178) {
		tmp = Math.cos(M) / Math.exp(l);
	} else if ((m <= 2.6e-290) || !(m <= 7.1e-227)) {
		tmp = t_0;
	} else {
		tmp = Math.exp(-l);
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.cos(M) * math.exp(-n)
	tmp = 0
	if m <= -54.0:
		tmp = math.pow(math.exp(m), (m * -0.25))
	elif m <= -1.25e-134:
		tmp = t_0
	elif m <= -2.9e-178:
		tmp = math.cos(M) / math.exp(l)
	elif (m <= 2.6e-290) or not (m <= 7.1e-227):
		tmp = t_0
	else:
		tmp = math.exp(-l)
	return tmp
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) * exp(Float64(-n)))
	tmp = 0.0
	if (m <= -54.0)
		tmp = exp(m) ^ Float64(m * -0.25);
	elseif (m <= -1.25e-134)
		tmp = t_0;
	elseif (m <= -2.9e-178)
		tmp = Float64(cos(M) / exp(l));
	elseif ((m <= 2.6e-290) || !(m <= 7.1e-227))
		tmp = t_0;
	else
		tmp = exp(Float64(-l));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = cos(M) * exp(-n);
	tmp = 0.0;
	if (m <= -54.0)
		tmp = exp(m) ^ (m * -0.25);
	elseif (m <= -1.25e-134)
		tmp = t_0;
	elseif (m <= -2.9e-178)
		tmp = cos(M) / exp(l);
	elseif ((m <= 2.6e-290) || ~((m <= 7.1e-227)))
		tmp = t_0;
	else
		tmp = exp(-l);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] * N[Exp[(-n)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[m, -54.0], N[Power[N[Exp[m], $MachinePrecision], N[(m * -0.25), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -1.25e-134], t$95$0, If[LessEqual[m, -2.9e-178], N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[m, 2.6e-290], N[Not[LessEqual[m, 7.1e-227]], $MachinePrecision]], t$95$0, N[Exp[(-l)], $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;m \leq -1.25 \cdot 10^{-134}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;m \leq 2.6 \cdot 10^{-290} \lor \neg \left(m \leq 7.1 \cdot 10^{-227}\right):\\
\;\;\;\;t_0\\

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


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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
      2. unpow298.1%

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
      3. associate-*r*98.1%

        \[\leadsto e^{\color{blue}{m \cdot \left(m \cdot -0.25\right)}} \]
      4. exp-prod98.1%

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

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

    if -54 < m < -1.2500000000000001e-134 or -2.8999999999999998e-178 < m < 2.60000000000000001e-290 or 7.0999999999999996e-227 < m

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.2500000000000001e-134 < m < -2.8999999999999998e-178

    1. Initial program 83.3%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\color{blue}{-\ell}} \]
      2. exp-neg67.6%

        \[\leadsto \cos M \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      3. associate-*r/67.6%

        \[\leadsto \color{blue}{\frac{\cos M \cdot 1}{e^{\ell}}} \]
      4. *-rgt-identity67.6%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    10. Simplified67.6%

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

    if 2.60000000000000001e-290 < m < 7.0999999999999996e-227

    1. Initial program 93.3%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;m \leq -54:\\ \;\;\;\;{\left(e^{m}\right)}^{\left(m \cdot -0.25\right)}\\ \mathbf{elif}\;m \leq -1.25 \cdot 10^{-134}:\\ \;\;\;\;\cos M \cdot e^{-n}\\ \mathbf{elif}\;m \leq -2.9 \cdot 10^{-178}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{elif}\;m \leq 2.6 \cdot 10^{-290} \lor \neg \left(m \leq 7.1 \cdot 10^{-227}\right):\\ \;\;\;\;\cos M \cdot e^{-n}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 5: 52.8% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{m}\\ \mathbf{if}\;n \leq -6.6 \cdot 10^{-286}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 1.65 \cdot 10^{-295}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{elif}\;n \leq 1.1 \cdot 10^{-264}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 720:\\ \;\;\;\;\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
 (let* ((t_0 (* (cos M) (exp m))))
   (if (<= n -6.6e-286)
     t_0
     (if (<= n 1.65e-295)
       (exp (- l))
       (if (<= n 1.1e-264)
         t_0
         (if (<= n 720.0)
           (* (cos M) (exp (* M (- M))))
           (* (cos M) (exp (- n)))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp(m);
	double tmp;
	if (n <= -6.6e-286) {
		tmp = t_0;
	} else if (n <= 1.65e-295) {
		tmp = exp(-l);
	} else if (n <= 1.1e-264) {
		tmp = t_0;
	} else if (n <= 720.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) :: t_0
    real(8) :: tmp
    t_0 = cos(m_1) * exp(m)
    if (n <= (-6.6d-286)) then
        tmp = t_0
    else if (n <= 1.65d-295) then
        tmp = exp(-l)
    else if (n <= 1.1d-264) then
        tmp = t_0
    else if (n <= 720.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 t_0 = Math.cos(M) * Math.exp(m);
	double tmp;
	if (n <= -6.6e-286) {
		tmp = t_0;
	} else if (n <= 1.65e-295) {
		tmp = Math.exp(-l);
	} else if (n <= 1.1e-264) {
		tmp = t_0;
	} else if (n <= 720.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):
	t_0 = math.cos(M) * math.exp(m)
	tmp = 0
	if n <= -6.6e-286:
		tmp = t_0
	elif n <= 1.65e-295:
		tmp = math.exp(-l)
	elif n <= 1.1e-264:
		tmp = t_0
	elif n <= 720.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)
	t_0 = Float64(cos(M) * exp(m))
	tmp = 0.0
	if (n <= -6.6e-286)
		tmp = t_0;
	elseif (n <= 1.65e-295)
		tmp = exp(Float64(-l));
	elseif (n <= 1.1e-264)
		tmp = t_0;
	elseif (n <= 720.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)
	t_0 = cos(M) * exp(m);
	tmp = 0.0;
	if (n <= -6.6e-286)
		tmp = t_0;
	elseif (n <= 1.65e-295)
		tmp = exp(-l);
	elseif (n <= 1.1e-264)
		tmp = t_0;
	elseif (n <= 720.0)
		tmp = cos(M) * exp((M * -M));
	else
		tmp = cos(M) * exp(-n);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] * N[Exp[m], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, -6.6e-286], t$95$0, If[LessEqual[n, 1.65e-295], N[Exp[(-l)], $MachinePrecision], If[LessEqual[n, 1.1e-264], t$95$0, If[LessEqual[n, 720.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}
t_0 := \cos M \cdot e^{m}\\
\mathbf{if}\;n \leq -6.6 \cdot 10^{-286}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 1.65 \cdot 10^{-295}:\\
\;\;\;\;e^{-\ell}\\

\mathbf{elif}\;n \leq 1.1 \cdot 10^{-264}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 720:\\
\;\;\;\;\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 4 regimes
  2. if n < -6.5999999999999997e-286 or 1.6499999999999999e-295 < n < 1.09999999999999997e-264

    1. Initial program 83.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{-\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} + \left(\ell - \color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}}\right)\right)} \]
      7. add-sqr-sqrt98.2%

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

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

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

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

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

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

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

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

    if -6.5999999999999997e-286 < n < 1.6499999999999999e-295

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    if 1.09999999999999997e-264 < n < 720

    1. Initial program 91.9%

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

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

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

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

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

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

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

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

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

    if 720 < n

    1. Initial program 66.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -6.6 \cdot 10^{-286}:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{elif}\;n \leq 1.65 \cdot 10^{-295}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{elif}\;n \leq 1.1 \cdot 10^{-264}:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{elif}\;n \leq 720:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-n}\\ \end{array} \]

Alternative 6: 75.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{\left(\left(m - n\right) - \ell\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(Float64(m - 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[(N[(m - n), $MachinePrecision] - l), $MachinePrecision] - N[(M * M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 52.7% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 3.5 \cdot 10^{-6}:\\
\;\;\;\;e^{-\ell}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 3.49999999999999995e-6

    1. Initial program 86.5%

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

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

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

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

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

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

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

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

    if 3.49999999999999995e-6 < n

    1. Initial program 67.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 36.2% 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 81.4%

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

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

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

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

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

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

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

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

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

Alternative 9: 7.1% accurate, 4.2× speedup?

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

\\
\cos M
\end{array}
Derivation
  1. Initial program 81.4%

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

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

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

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot n\right) - M\right)} \]
  6. Step-by-step derivation
    1. *-commutative9.6%

      \[\leadsto \cos \left(\color{blue}{\left(K \cdot n\right) \cdot 0.5} - M\right) \]
    2. associate-*l*9.6%

      \[\leadsto \cos \left(\color{blue}{K \cdot \left(n \cdot 0.5\right)} - M\right) \]
  7. Simplified9.6%

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  9. Step-by-step derivation
    1. cos-neg9.8%

      \[\leadsto \color{blue}{\cos M} \]
  10. Simplified9.8%

    \[\leadsto \color{blue}{\cos M} \]
  11. Final simplification9.8%

    \[\leadsto \cos M \]

Alternative 10: 6.9% accurate, 141.7× speedup?

\[\begin{array}{l} \\ 1 - \ell \end{array} \]
(FPCore (K m n M l) :precision binary64 (- 1.0 l))
double code(double K, double m, double n, double M, double l) {
	return 1.0 - 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 = 1.0d0 - l
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0 - l;
}
def code(K, m, n, M, l):
	return 1.0 - l
function code(K, m, n, M, l)
	return Float64(1.0 - l)
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0 - l;
end
code[K_, m_, n_, M_, l_] := N[(1.0 - l), $MachinePrecision]
\begin{array}{l}

\\
1 - \ell
\end{array}
Derivation
  1. Initial program 81.4%

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

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

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

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

    \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\right)\right)} \cdot e^{-\ell} \]
  6. Step-by-step derivation
    1. *-commutative37.4%

      \[\leadsto \cos \color{blue}{\left(\left(K \cdot m\right) \cdot 0.5\right)} \cdot e^{-\ell} \]
    2. *-commutative37.4%

      \[\leadsto \cos \left(\color{blue}{\left(m \cdot K\right)} \cdot 0.5\right) \cdot e^{-\ell} \]
    3. associate-*l*37.4%

      \[\leadsto \cos \color{blue}{\left(m \cdot \left(K \cdot 0.5\right)\right)} \cdot e^{-\ell} \]
  7. Simplified37.4%

    \[\leadsto \cos \color{blue}{\left(m \cdot \left(K \cdot 0.5\right)\right)} \cdot e^{-\ell} \]
  8. Taylor expanded in l around 0 9.4%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot m\right)\right) + -1 \cdot \left(\ell \cdot \cos \left(0.5 \cdot \left(K \cdot m\right)\right)\right)} \]
  9. Step-by-step derivation
    1. associate-*r*9.4%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\right)} + -1 \cdot \left(\ell \cdot \cos \left(0.5 \cdot \left(K \cdot m\right)\right)\right) \]
    2. *-commutative9.4%

      \[\leadsto \cos \color{blue}{\left(m \cdot \left(0.5 \cdot K\right)\right)} + -1 \cdot \left(\ell \cdot \cos \left(0.5 \cdot \left(K \cdot m\right)\right)\right) \]
    3. *-lft-identity9.4%

      \[\leadsto \color{blue}{1 \cdot \cos \left(m \cdot \left(0.5 \cdot K\right)\right)} + -1 \cdot \left(\ell \cdot \cos \left(0.5 \cdot \left(K \cdot m\right)\right)\right) \]
    4. associate-*r*9.4%

      \[\leadsto 1 \cdot \cos \left(m \cdot \left(0.5 \cdot K\right)\right) + \color{blue}{\left(-1 \cdot \ell\right) \cdot \cos \left(0.5 \cdot \left(K \cdot m\right)\right)} \]
    5. neg-mul-19.4%

      \[\leadsto 1 \cdot \cos \left(m \cdot \left(0.5 \cdot K\right)\right) + \color{blue}{\left(-\ell\right)} \cdot \cos \left(0.5 \cdot \left(K \cdot m\right)\right) \]
    6. associate-*r*9.4%

      \[\leadsto 1 \cdot \cos \left(m \cdot \left(0.5 \cdot K\right)\right) + \left(-\ell\right) \cdot \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\right)} \]
    7. *-commutative9.4%

      \[\leadsto 1 \cdot \cos \left(m \cdot \left(0.5 \cdot K\right)\right) + \left(-\ell\right) \cdot \cos \color{blue}{\left(m \cdot \left(0.5 \cdot K\right)\right)} \]
    8. distribute-rgt-out9.4%

      \[\leadsto \color{blue}{\cos \left(m \cdot \left(0.5 \cdot K\right)\right) \cdot \left(1 + \left(-\ell\right)\right)} \]
    9. *-commutative9.4%

      \[\leadsto \cos \color{blue}{\left(\left(0.5 \cdot K\right) \cdot m\right)} \cdot \left(1 + \left(-\ell\right)\right) \]
    10. associate-*r*9.4%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\right)\right)} \cdot \left(1 + \left(-\ell\right)\right) \]
    11. *-commutative9.4%

      \[\leadsto \cos \left(0.5 \cdot \color{blue}{\left(m \cdot K\right)}\right) \cdot \left(1 + \left(-\ell\right)\right) \]
    12. sub-neg9.4%

      \[\leadsto \cos \left(0.5 \cdot \left(m \cdot K\right)\right) \cdot \color{blue}{\left(1 - \ell\right)} \]
  10. Simplified9.4%

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(m \cdot K\right)\right) \cdot \left(1 - \ell\right)} \]
  11. Taylor expanded in m around 0 9.7%

    \[\leadsto \color{blue}{1 - \ell} \]
  12. Final simplification9.7%

    \[\leadsto 1 - \ell \]

Reproduce

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