Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 96.5%
Time: 16.6s
Alternatives: 13
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 76.3% accurate, 1.0× speedup?

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

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

Alternative 1: 96.5% accurate, 1.0× speedup?

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

\\
\cos M \cdot e^{\left|m - n\right| - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}
\end{array}
Derivation
  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. Step-by-step derivation
    1. associate-/l*69.7%

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

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

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

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

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

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

Alternative 2: 73.3% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;n \leq 68000:\\
\;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|m - n\right|\right) + \left(m \cdot m\right) \cdot 0.25}}\\

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


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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    8. Simplified68.7%

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

    if 68000 < n

    1. Initial program 57.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow297.0%

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

        \[\leadsto e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
      4. exp-prod97.0%

        \[\leadsto \color{blue}{{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}} \]
    14. Simplified97.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 68000:\\ \;\;\;\;\frac{\cos M}{e^{\left(\ell - \left|m - n\right|\right) + \left(m \cdot m\right) \cdot 0.25}}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 3: 68.4% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;n \leq -7.6 \cdot 10^{-295}:\\
\;\;\;\;e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\

\mathbf{elif}\;n \leq 4.3 \cdot 10^{-187}:\\
\;\;\;\;\frac{\cos \left(0.5 \cdot \left(n \cdot K\right) - M\right)}{e^{\ell}}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;e^{n \cdot \left(n \cdot 0.25\right) + n \cdot \left(\left(m \cdot 0.5 - M\right) + -1\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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

    1. Initial program 63.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative97.7%

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow297.7%

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

        \[\leadsto e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
      4. exp-prod97.7%

        \[\leadsto \color{blue}{{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}} \]
    14. Simplified97.7%

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

    if -55 < n < -7.60000000000000037e-295

    1. Initial program 78.8%

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

        \[\leadsto \cos \left(\color{blue}{\frac{K}{\frac{2}{m + n}}} - 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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, {m}^{2}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)}} \]
      2. unpow223.2%

        \[\leadsto e^{\mathsf{fma}\left(0.25, \color{blue}{m \cdot m}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)} \]
      3. *-commutative23.2%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, \color{blue}{m \cdot \left(\left(1 + 0.5 \cdot n\right) - M\right)}\right)} \]
      4. associate--l+23.2%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \color{blue}{\left(1 + \left(0.5 \cdot n - M\right)\right)}\right)} \]
      5. *-commutative23.2%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(\color{blue}{n \cdot 0.5} - M\right)\right)\right)} \]
    11. Simplified23.2%

      \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(n \cdot 0.5 - M\right)\right)\right)}} \]
    12. Taylor expanded in m around 0 49.1%

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

    if -7.60000000000000037e-295 < n < 4.3e-187

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

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

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

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

    if 4.3e-187 < n < 54

    1. Initial program 72.0%

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

        \[\leadsto \cos \left(\color{blue}{\frac{K}{\frac{2}{m + n}}} - 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.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{0.25 \cdot {n}^{2} + -1 \cdot \left(n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)\right)}} \]
      2. mul-1-neg32.2%

        \[\leadsto e^{0.25 \cdot {n}^{2} + \color{blue}{\left(-n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)\right)}} \]
      3. unsub-neg32.2%

        \[\leadsto e^{\color{blue}{0.25 \cdot {n}^{2} - n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)}} \]
      4. unpow232.2%

        \[\leadsto e^{0.25 \cdot \color{blue}{\left(n \cdot n\right)} - n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)} \]
      5. associate-*r*32.2%

        \[\leadsto e^{\color{blue}{\left(0.25 \cdot n\right) \cdot n} - n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)} \]
      6. mul-1-neg32.2%

        \[\leadsto e^{\left(0.25 \cdot n\right) \cdot n - n \cdot \left(1 + \color{blue}{\left(-\left(0.5 \cdot m - M\right)\right)}\right)} \]
      7. unsub-neg32.2%

        \[\leadsto e^{\left(0.25 \cdot n\right) \cdot n - n \cdot \color{blue}{\left(1 - \left(0.5 \cdot m - M\right)\right)}} \]
      8. *-commutative32.2%

        \[\leadsto e^{\left(0.25 \cdot n\right) \cdot n - n \cdot \left(1 - \left(\color{blue}{m \cdot 0.5} - M\right)\right)} \]
    11. Simplified32.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -55:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \mathbf{elif}\;n \leq -7.6 \cdot 10^{-295}:\\ \;\;\;\;e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\ \mathbf{elif}\;n \leq 4.3 \cdot 10^{-187}:\\ \;\;\;\;\frac{\cos \left(0.5 \cdot \left(n \cdot K\right) - M\right)}{e^{\ell}}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;e^{n \cdot \left(n \cdot 0.25\right) + n \cdot \left(\left(m \cdot 0.5 - M\right) + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 4: 61.3% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\left|m - n\right| - \left(m \cdot m\right) \cdot 0.25}\\ \mathbf{if}\;n \leq 5.6 \cdot 10^{-289}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 7.5 \cdot 10^{-224}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (- (fabs (- m n)) (* (* m m) 0.25)))))
   (if (<= n 5.6e-289)
     t_0
     (if (<= n 7.5e-224)
       (/ (cos M) (exp l))
       (if (<= n 54.0) t_0 (pow (exp n) (* n -0.25)))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((fabs((m - n)) - ((m * m) * 0.25)));
	double tmp;
	if (n <= 5.6e-289) {
		tmp = t_0;
	} else if (n <= 7.5e-224) {
		tmp = cos(M) / exp(l);
	} else if (n <= 54.0) {
		tmp = t_0;
	} else {
		tmp = pow(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) :: t_0
    real(8) :: tmp
    t_0 = exp((abs((m - n)) - ((m * m) * 0.25d0)))
    if (n <= 5.6d-289) then
        tmp = t_0
    else if (n <= 7.5d-224) then
        tmp = cos(m_1) / exp(l)
    else if (n <= 54.0d0) then
        tmp = t_0
    else
        tmp = 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 t_0 = Math.exp((Math.abs((m - n)) - ((m * m) * 0.25)));
	double tmp;
	if (n <= 5.6e-289) {
		tmp = t_0;
	} else if (n <= 7.5e-224) {
		tmp = Math.cos(M) / Math.exp(l);
	} else if (n <= 54.0) {
		tmp = t_0;
	} else {
		tmp = Math.pow(Math.exp(n), (n * -0.25));
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((math.fabs((m - n)) - ((m * m) * 0.25)))
	tmp = 0
	if n <= 5.6e-289:
		tmp = t_0
	elif n <= 7.5e-224:
		tmp = math.cos(M) / math.exp(l)
	elif n <= 54.0:
		tmp = t_0
	else:
		tmp = math.pow(math.exp(n), (n * -0.25))
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(abs(Float64(m - n)) - Float64(Float64(m * m) * 0.25)))
	tmp = 0.0
	if (n <= 5.6e-289)
		tmp = t_0;
	elseif (n <= 7.5e-224)
		tmp = Float64(cos(M) / exp(l));
	elseif (n <= 54.0)
		tmp = t_0;
	else
		tmp = exp(n) ^ Float64(n * -0.25);
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp((abs((m - n)) - ((m * m) * 0.25)));
	tmp = 0.0;
	if (n <= 5.6e-289)
		tmp = t_0;
	elseif (n <= 7.5e-224)
		tmp = cos(M) / exp(l);
	elseif (n <= 54.0)
		tmp = t_0;
	else
		tmp = exp(n) ^ (n * -0.25);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(N[(m * m), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, 5.6e-289], t$95$0, If[LessEqual[n, 7.5e-224], N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 54.0], t$95$0, N[Power[N[Exp[n], $MachinePrecision], N[(n * -0.25), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\left|m - n\right| - \left(m \cdot m\right) \cdot 0.25}\\
\mathbf{if}\;n \leq 5.6 \cdot 10^{-289}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;n \leq 7.5 \cdot 10^{-224}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < 5.5999999999999997e-289 or 7.49999999999999978e-224 < n < 54

    1. Initial program 73.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. Simplified73.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{e^{\left(\ell + 0.25 \cdot {m}^{2}\right) - \left|n - m\right|}}} \]
    10. Step-by-step derivation
      1. rec-exp66.7%

        \[\leadsto \color{blue}{e^{-\left(\left(\ell + 0.25 \cdot {m}^{2}\right) - \left|n - m\right|\right)}} \]
      2. associate--l+66.7%

        \[\leadsto e^{-\color{blue}{\left(\ell + \left(0.25 \cdot {m}^{2} - \left|n - m\right|\right)\right)}} \]
      3. associate--l+66.7%

        \[\leadsto e^{-\color{blue}{\left(\left(\ell + 0.25 \cdot {m}^{2}\right) - \left|n - m\right|\right)}} \]
      4. unpow266.7%

        \[\leadsto e^{-\left(\left(\ell + 0.25 \cdot \color{blue}{\left(m \cdot m\right)}\right) - \left|n - m\right|\right)} \]
    11. Simplified66.7%

      \[\leadsto \color{blue}{e^{-\left(\left(\ell + 0.25 \cdot \left(m \cdot m\right)\right) - \left|n - m\right|\right)}} \]
    12. Taylor expanded in l around 0 55.7%

      \[\leadsto e^{-\color{blue}{\left(0.25 \cdot {m}^{2} - \left|n - m\right|\right)}} \]
    13. Step-by-step derivation
      1. unpow255.7%

        \[\leadsto e^{-\left(0.25 \cdot \color{blue}{\left(m \cdot m\right)} - \left|n - m\right|\right)} \]
      2. fabs-sub55.7%

        \[\leadsto e^{-\left(0.25 \cdot \left(m \cdot m\right) - \color{blue}{\left|m - n\right|}\right)} \]
    14. Simplified55.7%

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

    if 5.5999999999999997e-289 < n < 7.49999999999999978e-224

    1. Initial program 82.0%

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

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

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

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

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

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

    if 54 < n

    1. Initial program 57.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow297.0%

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

        \[\leadsto e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
      4. exp-prod97.0%

        \[\leadsto \color{blue}{{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}} \]
    14. Simplified97.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 5.6 \cdot 10^{-289}:\\ \;\;\;\;e^{\left|m - n\right| - \left(m \cdot m\right) \cdot 0.25}\\ \mathbf{elif}\;n \leq 7.5 \cdot 10^{-224}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;e^{\left|m - n\right| - \left(m \cdot m\right) \cdot 0.25}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 5: 73.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 68000:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + \left(m \cdot m\right) \cdot 0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 68000.0)
   (exp (- (fabs (- m n)) (+ l (* (* m m) 0.25))))
   (pow (exp n) (* n -0.25))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 68000.0) {
		tmp = exp((fabs((m - n)) - (l + ((m * m) * 0.25))));
	} else {
		tmp = pow(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 <= 68000.0d0) then
        tmp = exp((abs((m - n)) - (l + ((m * m) * 0.25d0))))
    else
        tmp = 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 <= 68000.0) {
		tmp = Math.exp((Math.abs((m - n)) - (l + ((m * m) * 0.25))));
	} else {
		tmp = Math.pow(Math.exp(n), (n * -0.25));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if n <= 68000.0:
		tmp = math.exp((math.fabs((m - n)) - (l + ((m * m) * 0.25))))
	else:
		tmp = math.pow(math.exp(n), (n * -0.25))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (n <= 68000.0)
		tmp = exp(Float64(abs(Float64(m - n)) - Float64(l + Float64(Float64(m * m) * 0.25))));
	else
		tmp = exp(n) ^ Float64(n * -0.25);
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (n <= 68000.0)
		tmp = exp((abs((m - n)) - (l + ((m * m) * 0.25))));
	else
		tmp = exp(n) ^ (n * -0.25);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 68000.0], N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(l + N[(N[(m * m), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Power[N[Exp[n], $MachinePrecision], N[(n * -0.25), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n \leq 68000:\\
\;\;\;\;e^{\left|m - n\right| - \left(\ell + \left(m \cdot m\right) \cdot 0.25\right)}\\

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


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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    8. Simplified68.7%

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

      \[\leadsto \color{blue}{\frac{1}{e^{\left(\ell + 0.25 \cdot {m}^{2}\right) - \left|n - m\right|}}} \]
    10. Step-by-step derivation
      1. rec-exp68.2%

        \[\leadsto \color{blue}{e^{-\left(\left(\ell + 0.25 \cdot {m}^{2}\right) - \left|n - m\right|\right)}} \]
      2. associate--l+68.2%

        \[\leadsto e^{-\color{blue}{\left(\ell + \left(0.25 \cdot {m}^{2} - \left|n - m\right|\right)\right)}} \]
      3. associate--l+68.2%

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

        \[\leadsto e^{-\left(\left(\ell + 0.25 \cdot \color{blue}{\left(m \cdot m\right)}\right) - \left|n - m\right|\right)} \]
    11. Simplified68.2%

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

    if 68000 < n

    1. Initial program 57.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow297.0%

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

        \[\leadsto e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
      4. exp-prod97.0%

        \[\leadsto \color{blue}{{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}} \]
    14. Simplified97.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 68000:\\ \;\;\;\;e^{\left|m - n\right| - \left(\ell + \left(m \cdot m\right) \cdot 0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 6: 68.6% accurate, 2.0× speedup?

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

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

\mathbf{elif}\;n \leq -7.6 \cdot 10^{-295}:\\
\;\;\;\;e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\

\mathbf{elif}\;n \leq 1.4 \cdot 10^{-180}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

\mathbf{elif}\;n \leq 54:\\
\;\;\;\;e^{n \cdot \left(n \cdot 0.25\right) + n \cdot \left(\left(m \cdot 0.5 - M\right) + -1\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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

    1. Initial program 63.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{e^{-0.25 \cdot {n}^{2}}} \]
    13. Step-by-step derivation
      1. *-commutative97.7%

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot -0.25}} \]
      2. unpow297.7%

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

        \[\leadsto e^{\color{blue}{n \cdot \left(n \cdot -0.25\right)}} \]
      4. exp-prod97.7%

        \[\leadsto \color{blue}{{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}} \]
    14. Simplified97.7%

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

    if -52 < n < -7.60000000000000037e-295

    1. Initial program 78.8%

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

        \[\leadsto \cos \left(\color{blue}{\frac{K}{\frac{2}{m + n}}} - 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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, {m}^{2}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)}} \]
      2. unpow223.2%

        \[\leadsto e^{\mathsf{fma}\left(0.25, \color{blue}{m \cdot m}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)} \]
      3. *-commutative23.2%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, \color{blue}{m \cdot \left(\left(1 + 0.5 \cdot n\right) - M\right)}\right)} \]
      4. associate--l+23.2%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \color{blue}{\left(1 + \left(0.5 \cdot n - M\right)\right)}\right)} \]
      5. *-commutative23.2%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(\color{blue}{n \cdot 0.5} - M\right)\right)\right)} \]
    11. Simplified23.2%

      \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(n \cdot 0.5 - M\right)\right)\right)}} \]
    12. Taylor expanded in m around 0 49.1%

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

    if -7.60000000000000037e-295 < n < 1.39999999999999999e-180

    1. Initial program 73.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. Simplified73.8%

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

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

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

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

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

    if 1.39999999999999999e-180 < n < 54

    1. Initial program 73.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{0.25 \cdot {n}^{2} + -1 \cdot \left(n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)\right)}} \]
      2. mul-1-neg34.1%

        \[\leadsto e^{0.25 \cdot {n}^{2} + \color{blue}{\left(-n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)\right)}} \]
      3. unsub-neg34.1%

        \[\leadsto e^{\color{blue}{0.25 \cdot {n}^{2} - n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)}} \]
      4. unpow234.1%

        \[\leadsto e^{0.25 \cdot \color{blue}{\left(n \cdot n\right)} - n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)} \]
      5. associate-*r*34.1%

        \[\leadsto e^{\color{blue}{\left(0.25 \cdot n\right) \cdot n} - n \cdot \left(1 + -1 \cdot \left(0.5 \cdot m - M\right)\right)} \]
      6. mul-1-neg34.1%

        \[\leadsto e^{\left(0.25 \cdot n\right) \cdot n - n \cdot \left(1 + \color{blue}{\left(-\left(0.5 \cdot m - M\right)\right)}\right)} \]
      7. unsub-neg34.1%

        \[\leadsto e^{\left(0.25 \cdot n\right) \cdot n - n \cdot \color{blue}{\left(1 - \left(0.5 \cdot m - M\right)\right)}} \]
      8. *-commutative34.1%

        \[\leadsto e^{\left(0.25 \cdot n\right) \cdot n - n \cdot \left(1 - \left(\color{blue}{m \cdot 0.5} - M\right)\right)} \]
    11. Simplified34.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -52:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \mathbf{elif}\;n \leq -7.6 \cdot 10^{-295}:\\ \;\;\;\;e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\ \mathbf{elif}\;n \leq 1.4 \cdot 10^{-180}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;e^{n \cdot \left(n \cdot 0.25\right) + n \cdot \left(\left(m \cdot 0.5 - M\right) + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]

Alternative 7: 55.5% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 0.8:\\
\;\;\;\;e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 0.80000000000000004

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{0.25 \cdot {m}^{2} + \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m}} \]
    10. Step-by-step derivation
      1. fma-def24.6%

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

        \[\leadsto e^{\mathsf{fma}\left(0.25, \color{blue}{m \cdot m}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)} \]
      3. *-commutative24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, \color{blue}{m \cdot \left(\left(1 + 0.5 \cdot n\right) - M\right)}\right)} \]
      4. associate--l+24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \color{blue}{\left(1 + \left(0.5 \cdot n - M\right)\right)}\right)} \]
      5. *-commutative24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(\color{blue}{n \cdot 0.5} - M\right)\right)\right)} \]
    11. Simplified24.6%

      \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(n \cdot 0.5 - M\right)\right)\right)}} \]
    12. Taylor expanded in m around 0 44.6%

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

    if 0.80000000000000004 < l

    1. Initial program 71.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. Simplified71.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 0.8:\\ \;\;\;\;e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \end{array} \]

Alternative 8: 55.5% accurate, 3.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 0.75:\\
\;\;\;\;e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 0.75

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{0.25 \cdot {m}^{2} + \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m}} \]
    10. Step-by-step derivation
      1. fma-def24.6%

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

        \[\leadsto e^{\mathsf{fma}\left(0.25, \color{blue}{m \cdot m}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)} \]
      3. *-commutative24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, \color{blue}{m \cdot \left(\left(1 + 0.5 \cdot n\right) - M\right)}\right)} \]
      4. associate--l+24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \color{blue}{\left(1 + \left(0.5 \cdot n - M\right)\right)}\right)} \]
      5. *-commutative24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(\color{blue}{n \cdot 0.5} - M\right)\right)\right)} \]
    11. Simplified24.6%

      \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(n \cdot 0.5 - M\right)\right)\right)}} \]
    12. Taylor expanded in m around 0 44.6%

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

    if 0.75 < l

    1. Initial program 71.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. Simplified71.6%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Taylor expanded in M around 0 97.9%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    8. Step-by-step derivation
      1. rec-exp97.9%

        \[\leadsto \color{blue}{e^{-\ell}} \]
    9. Simplified97.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 0.75:\\ \;\;\;\;e^{m \cdot \left(\left(n \cdot 0.5 + 1\right) - M\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 9: 48.4% accurate, 3.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 4.2 \cdot 10^{-300}:\\
\;\;\;\;e^{n \cdot \left(m \cdot 0.5\right)}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < 4.20000000000000007e-300

    1. Initial program 70.6%

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

        \[\leadsto \cos \left(\color{blue}{\frac{K}{\frac{2}{m + n}}} - 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.6%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{0.25 \cdot {m}^{2} + \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m}} \]
    10. Step-by-step derivation
      1. fma-def24.3%

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

        \[\leadsto e^{\mathsf{fma}\left(0.25, \color{blue}{m \cdot m}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)} \]
      3. *-commutative24.3%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, \color{blue}{m \cdot \left(\left(1 + 0.5 \cdot n\right) - M\right)}\right)} \]
      4. associate--l+24.3%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \color{blue}{\left(1 + \left(0.5 \cdot n - M\right)\right)}\right)} \]
      5. *-commutative24.3%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(\color{blue}{n \cdot 0.5} - M\right)\right)\right)} \]
    11. Simplified24.3%

      \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(n \cdot 0.5 - M\right)\right)\right)}} \]
    12. Taylor expanded in n around inf 34.1%

      \[\leadsto e^{\color{blue}{0.5 \cdot \left(n \cdot m\right)}} \]
    13. Step-by-step derivation
      1. *-commutative34.1%

        \[\leadsto e^{\color{blue}{\left(n \cdot m\right) \cdot 0.5}} \]
      2. associate-*l*34.1%

        \[\leadsto e^{\color{blue}{n \cdot \left(m \cdot 0.5\right)}} \]
    14. Simplified34.1%

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

    if 4.20000000000000007e-300 < l < 0.0040000000000000001

    1. Initial program 66.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, {m}^{2}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)}} \]
      2. unpow225.1%

        \[\leadsto e^{\mathsf{fma}\left(0.25, \color{blue}{m \cdot m}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)} \]
      3. *-commutative25.1%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, \color{blue}{m \cdot \left(\left(1 + 0.5 \cdot n\right) - M\right)}\right)} \]
      4. associate--l+25.1%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \color{blue}{\left(1 + \left(0.5 \cdot n - M\right)\right)}\right)} \]
      5. *-commutative25.1%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(\color{blue}{n \cdot 0.5} - M\right)\right)\right)} \]
    11. Simplified25.1%

      \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(n \cdot 0.5 - M\right)\right)\right)}} \]
    12. Taylor expanded in M around inf 37.6%

      \[\leadsto e^{\color{blue}{-1 \cdot \left(m \cdot M\right)}} \]
    13. Step-by-step derivation
      1. associate-*r*37.6%

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

        \[\leadsto e^{\color{blue}{\left(-m\right)} \cdot M} \]
    14. Simplified37.6%

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

    if 0.0040000000000000001 < l

    1. Initial program 71.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. Simplified71.6%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Taylor expanded in M around 0 97.9%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    8. Step-by-step derivation
      1. rec-exp97.9%

        \[\leadsto \color{blue}{e^{-\ell}} \]
    9. Simplified97.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 4.2 \cdot 10^{-300}:\\ \;\;\;\;e^{n \cdot \left(m \cdot 0.5\right)}\\ \mathbf{elif}\;\ell \leq 0.004:\\ \;\;\;\;e^{M \cdot \left(-m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 10: 48.5% accurate, 4.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 0.409999999999999976

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{0.25 \cdot {m}^{2} + \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m}} \]
    10. Step-by-step derivation
      1. fma-def24.6%

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

        \[\leadsto e^{\mathsf{fma}\left(0.25, \color{blue}{m \cdot m}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)} \]
      3. *-commutative24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, \color{blue}{m \cdot \left(\left(1 + 0.5 \cdot n\right) - M\right)}\right)} \]
      4. associate--l+24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \color{blue}{\left(1 + \left(0.5 \cdot n - M\right)\right)}\right)} \]
      5. *-commutative24.6%

        \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(\color{blue}{n \cdot 0.5} - M\right)\right)\right)} \]
    11. Simplified24.6%

      \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(n \cdot 0.5 - M\right)\right)\right)}} \]
    12. Taylor expanded in M around inf 30.4%

      \[\leadsto e^{\color{blue}{-1 \cdot \left(m \cdot M\right)}} \]
    13. Step-by-step derivation
      1. associate-*r*30.4%

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

        \[\leadsto e^{\color{blue}{\left(-m\right)} \cdot M} \]
    14. Simplified30.4%

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

    if 0.409999999999999976 < l

    1. Initial program 71.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. Simplified71.6%

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

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

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

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

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    7. Taylor expanded in M around 0 97.9%

      \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
    8. Step-by-step derivation
      1. rec-exp97.9%

        \[\leadsto \color{blue}{e^{-\ell}} \]
    9. Simplified97.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 0.41:\\ \;\;\;\;e^{M \cdot \left(-m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]

Alternative 11: 34.9% 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 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. Simplified69.8%

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

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

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

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

    \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
  7. Taylor expanded in M around 0 36.2%

    \[\leadsto \color{blue}{\frac{1}{e^{\ell}}} \]
  8. Step-by-step derivation
    1. rec-exp36.2%

      \[\leadsto \color{blue}{e^{-\ell}} \]
  9. Simplified36.2%

    \[\leadsto \color{blue}{e^{-\ell}} \]
  10. Final simplification36.2%

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

Alternative 12: 6.9% 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 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. Simplified69.8%

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

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

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

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

    \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
  7. Taylor expanded in l around 0 8.1%

    \[\leadsto \color{blue}{\cos M} \]
  8. Final simplification8.1%

    \[\leadsto \cos M \]

Alternative 13: 6.9% accurate, 425.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 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. Step-by-step derivation
    1. associate-/l*69.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto e^{\color{blue}{0.25 \cdot {m}^{2} + \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m}} \]
  10. Step-by-step derivation
    1. fma-def23.0%

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

      \[\leadsto e^{\mathsf{fma}\left(0.25, \color{blue}{m \cdot m}, \left(\left(1 + 0.5 \cdot n\right) - M\right) \cdot m\right)} \]
    3. *-commutative23.0%

      \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, \color{blue}{m \cdot \left(\left(1 + 0.5 \cdot n\right) - M\right)}\right)} \]
    4. associate--l+23.0%

      \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \color{blue}{\left(1 + \left(0.5 \cdot n - M\right)\right)}\right)} \]
    5. *-commutative23.0%

      \[\leadsto e^{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(\color{blue}{n \cdot 0.5} - M\right)\right)\right)} \]
  11. Simplified23.0%

    \[\leadsto e^{\color{blue}{\mathsf{fma}\left(0.25, m \cdot m, m \cdot \left(1 + \left(n \cdot 0.5 - M\right)\right)\right)}} \]
  12. Taylor expanded in m around 0 8.1%

    \[\leadsto \color{blue}{1} \]
  13. Final simplification8.1%

    \[\leadsto 1 \]

Reproduce

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