Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.3% → 94.9%
Time: 13.1s
Alternatives: 8
Speedup: 2.8×

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 8 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: 94.9% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos M \cdot e^{M \cdot \left(0 - M\right)}\\ \mathbf{if}\;M \leq -3.7 \cdot 10^{-9}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;M \leq 2400:\\ \;\;\;\;e^{\left|m - n\right| - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* (cos M) (exp (* M (- 0.0 M))))))
   (if (<= M -3.7e-9)
     t_0
     (if (<= M 2400.0)
       (exp (- (fabs (- m n)) (fma 0.25 (* (+ m n) (+ m n)) l)))
       t_0))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = cos(M) * exp((M * (0.0 - M)));
	double tmp;
	if (M <= -3.7e-9) {
		tmp = t_0;
	} else if (M <= 2400.0) {
		tmp = exp((fabs((m - n)) - fma(0.25, ((m + n) * (m + n)), l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = Float64(cos(M) * exp(Float64(M * Float64(0.0 - M))))
	tmp = 0.0
	if (M <= -3.7e-9)
		tmp = t_0;
	elseif (M <= 2400.0)
		tmp = exp(Float64(abs(Float64(m - n)) - fma(0.25, Float64(Float64(m + n) * Float64(m + n)), l)));
	else
		tmp = t_0;
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(M * N[(0.0 - M), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[M, -3.7e-9], t$95$0, If[LessEqual[M, 2400.0], N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos M \cdot e^{M \cdot \left(0 - M\right)}\\
\mathbf{if}\;M \leq -3.7 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;M \leq 2400:\\
\;\;\;\;e^{\left|m - n\right| - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < -3.7e-9 or 2400 < M

    1. Initial program 81.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. Add Preprocessing
    3. Taylor expanded in K around 0

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

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

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot {M}^{2}}} \]
    7. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \cos M \cdot e^{\color{blue}{\mathsf{neg}\left({M}^{2}\right)}} \]
      2. neg-sub0N/A

        \[\leadsto \cos M \cdot e^{\color{blue}{0 - {M}^{2}}} \]
      3. --lowering--.f64N/A

        \[\leadsto \cos M \cdot e^{\color{blue}{0 - {M}^{2}}} \]
      4. unpow2N/A

        \[\leadsto \cos M \cdot e^{0 - \color{blue}{M \cdot M}} \]
      5. *-lowering-*.f6497.0

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

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

    if -3.7e-9 < M < 2400

    1. Initial program 71.7%

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

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    7. Step-by-step derivation
      1. exp-lowering-exp.f64N/A

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

        \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
      3. fabs-subN/A

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      4. sub-negN/A

        \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      5. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      6. fabs-lowering-fabs.f64N/A

        \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      7. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      8. sub-negN/A

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

        \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      10. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      11. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
      12. unpow2N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      13. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      14. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      15. +-lowering-+.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      16. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
      17. +-lowering-+.f6495.0

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    8. Simplified95.0%

      \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \left(n + m\right), \ell\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -3.7 \cdot 10^{-9}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(0 - M\right)}\\ \mathbf{elif}\;M \leq 2400:\\ \;\;\;\;e^{\left|m - n\right| - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(0 - M\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.6% accurate, 1.1× speedup?

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

\\
\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 76.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. Add Preprocessing
  3. Taylor expanded in K around 0

    \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
  4. Step-by-step derivation
    1. cos-negN/A

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

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

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

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

Alternative 3: 87.8% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left|m - n\right|\\ \mathbf{if}\;M \leq -1.55 \cdot 10^{-9}:\\ \;\;\;\;e^{t\_0 - n \cdot \left(n \cdot \mathsf{fma}\left(m, \mathsf{fma}\left(0.25, \frac{m}{n \cdot n}, \frac{0.5}{n}\right), 0.25\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{t\_0 - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (fabs (- m n))))
   (if (<= M -1.55e-9)
     (exp (- t_0 (* n (* n (fma m (fma 0.25 (/ m (* n n)) (/ 0.5 n)) 0.25)))))
     (exp (- t_0 (fma 0.25 (* (+ m n) (+ m n)) l))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = fabs((m - n));
	double tmp;
	if (M <= -1.55e-9) {
		tmp = exp((t_0 - (n * (n * fma(m, fma(0.25, (m / (n * n)), (0.5 / n)), 0.25)))));
	} else {
		tmp = exp((t_0 - fma(0.25, ((m + n) * (m + n)), l)));
	}
	return tmp;
}
function code(K, m, n, M, l)
	t_0 = abs(Float64(m - n))
	tmp = 0.0
	if (M <= -1.55e-9)
		tmp = exp(Float64(t_0 - Float64(n * Float64(n * fma(m, fma(0.25, Float64(m / Float64(n * n)), Float64(0.5 / n)), 0.25)))));
	else
		tmp = exp(Float64(t_0 - fma(0.25, Float64(Float64(m + n) * Float64(m + n)), l)));
	end
	return tmp
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[M, -1.55e-9], N[Exp[N[(t$95$0 - N[(n * N[(n * N[(m * N[(0.25 * N[(m / N[(n * n), $MachinePrecision]), $MachinePrecision] + N[(0.5 / n), $MachinePrecision]), $MachinePrecision] + 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(t$95$0 - N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left|m - n\right|\\
\mathbf{if}\;M \leq -1.55 \cdot 10^{-9}:\\
\;\;\;\;e^{t\_0 - n \cdot \left(n \cdot \mathsf{fma}\left(m, \mathsf{fma}\left(0.25, \frac{m}{n \cdot n}, \frac{0.5}{n}\right), 0.25\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{t\_0 - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)}\\


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

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in K around 0

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    7. Step-by-step derivation
      1. exp-lowering-exp.f64N/A

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

        \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
      3. fabs-subN/A

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      4. sub-negN/A

        \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      5. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      6. fabs-lowering-fabs.f64N/A

        \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      7. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      8. sub-negN/A

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

        \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      10. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      11. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
      12. unpow2N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      13. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      14. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      15. +-lowering-+.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      16. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
      17. +-lowering-+.f6472.9

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    8. Simplified72.9%

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

      \[\leadsto e^{\left|n - m\right| - \color{blue}{{n}^{2} \cdot \left(\frac{1}{4} + \left(\frac{1}{4} \cdot \frac{{m}^{2}}{{n}^{2}} + \left(\frac{1}{2} \cdot \frac{m}{n} + \frac{\ell}{{n}^{2}}\right)\right)\right)}} \]
    10. Step-by-step derivation
      1. unpow2N/A

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

        \[\leadsto e^{\left|n - m\right| - \color{blue}{n \cdot \left(n \cdot \left(\frac{1}{4} + \left(\frac{1}{4} \cdot \frac{{m}^{2}}{{n}^{2}} + \left(\frac{1}{2} \cdot \frac{m}{n} + \frac{\ell}{{n}^{2}}\right)\right)\right)\right)}} \]
      3. *-lowering-*.f64N/A

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

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

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

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\left(\frac{1}{4} + \color{blue}{\frac{{m}^{2}}{{n}^{2}} \cdot \frac{1}{4}}\right) + \left(\frac{1}{2} \cdot \frac{m}{n} + \frac{\ell}{{n}^{2}}\right)\right)\right)} \]
      7. distribute-rgt1-inN/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\color{blue}{\left(\frac{{m}^{2}}{{n}^{2}} + 1\right) \cdot \frac{1}{4}} + \left(\frac{1}{2} \cdot \frac{m}{n} + \frac{\ell}{{n}^{2}}\right)\right)\right)} \]
      8. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \color{blue}{\mathsf{fma}\left(\frac{{m}^{2}}{{n}^{2}} + 1, \frac{1}{4}, \frac{1}{2} \cdot \frac{m}{n} + \frac{\ell}{{n}^{2}}\right)}\right)} \]
    11. Simplified70.0%

      \[\leadsto e^{\left|n - m\right| - \color{blue}{n \cdot \left(n \cdot \mathsf{fma}\left(\mathsf{fma}\left(m, \frac{m}{n \cdot n}, 1\right), 0.25, \mathsf{fma}\left(m, \frac{0.5}{n}, \frac{\ell}{n \cdot n}\right)\right)\right)}} \]
    12. Taylor expanded in l around 0

      \[\leadsto e^{\left|n - m\right| - n \cdot \color{blue}{\left(n \cdot \left(\frac{1}{4} \cdot \left(1 + \frac{{m}^{2}}{{n}^{2}}\right) + \frac{1}{2} \cdot \frac{m}{n}\right)\right)}} \]
    13. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \color{blue}{\left(n \cdot \left(\frac{1}{4} \cdot \left(1 + \frac{{m}^{2}}{{n}^{2}}\right) + \frac{1}{2} \cdot \frac{m}{n}\right)\right)}} \]
      2. distribute-lft-inN/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\color{blue}{\left(\frac{1}{4} \cdot 1 + \frac{1}{4} \cdot \frac{{m}^{2}}{{n}^{2}}\right)} + \frac{1}{2} \cdot \frac{m}{n}\right)\right)} \]
      3. metadata-evalN/A

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

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\left(\frac{1}{4} + \color{blue}{\frac{\frac{1}{4} \cdot {m}^{2}}{{n}^{2}}}\right) + \frac{1}{2} \cdot \frac{m}{n}\right)\right)} \]
      5. unpow2N/A

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

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\left(\frac{1}{4} + \frac{\color{blue}{\left(\frac{1}{4} \cdot m\right) \cdot m}}{{n}^{2}}\right) + \frac{1}{2} \cdot \frac{m}{n}\right)\right)} \]
      7. associate-*l/N/A

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

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

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\left(\frac{1}{4} + \left(\frac{1}{4} \cdot \frac{m}{{n}^{2}}\right) \cdot m\right) + \color{blue}{\frac{\frac{1}{2} \cdot m}{n}}\right)\right)} \]
      10. associate-*l/N/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\left(\frac{1}{4} + \left(\frac{1}{4} \cdot \frac{m}{{n}^{2}}\right) \cdot m\right) + \color{blue}{\frac{\frac{1}{2}}{n} \cdot m}\right)\right)} \]
      11. metadata-evalN/A

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

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\left(\frac{1}{4} + \left(\frac{1}{4} \cdot \frac{m}{{n}^{2}}\right) \cdot m\right) + \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{n}\right)} \cdot m\right)\right)} \]
      13. associate-+r+N/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \color{blue}{\left(\frac{1}{4} + \left(\left(\frac{1}{4} \cdot \frac{m}{{n}^{2}}\right) \cdot m + \left(\frac{1}{2} \cdot \frac{1}{n}\right) \cdot m\right)\right)}\right)} \]
      14. distribute-rgt-inN/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \left(\frac{1}{4} + \color{blue}{m \cdot \left(\frac{1}{4} \cdot \frac{m}{{n}^{2}} + \frac{1}{2} \cdot \frac{1}{n}\right)}\right)\right)} \]
      15. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \color{blue}{\left(m \cdot \left(\frac{1}{4} \cdot \frac{m}{{n}^{2}} + \frac{1}{2} \cdot \frac{1}{n}\right) + \frac{1}{4}\right)}\right)} \]
      16. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - n \cdot \left(n \cdot \color{blue}{\mathsf{fma}\left(m, \frac{1}{4} \cdot \frac{m}{{n}^{2}} + \frac{1}{2} \cdot \frac{1}{n}, \frac{1}{4}\right)}\right)} \]
    14. Simplified83.1%

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

    if -1.55000000000000002e-9 < M

    1. Initial program 76.2%

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

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    7. Step-by-step derivation
      1. exp-lowering-exp.f64N/A

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

        \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
      3. fabs-subN/A

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      4. sub-negN/A

        \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      5. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      6. fabs-lowering-fabs.f64N/A

        \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      7. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      8. sub-negN/A

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

        \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      10. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      11. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
      12. unpow2N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      13. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      14. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      15. +-lowering-+.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      16. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
      17. +-lowering-+.f6490.4

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    8. Simplified90.4%

      \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \left(n + m\right), \ell\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq -1.55 \cdot 10^{-9}:\\ \;\;\;\;e^{\left|m - n\right| - n \cdot \left(n \cdot \mathsf{fma}\left(m, \mathsf{fma}\left(0.25, \frac{m}{n \cdot n}, \frac{0.5}{n}\right), 0.25\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\left|m - n\right| - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 86.6% accurate, 2.8× speedup?

\[\begin{array}{l} \\ e^{\left|m - n\right| - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (exp (- (fabs (- m n)) (fma 0.25 (* (+ m n) (+ m n)) l))))
double code(double K, double m, double n, double M, double l) {
	return exp((fabs((m - n)) - fma(0.25, ((m + n) * (m + n)), l)));
}
function code(K, m, n, M, l)
	return exp(Float64(abs(Float64(m - n)) - fma(0.25, Float64(Float64(m + n) * Float64(m + n)), l)))
end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\left|m - n\right| - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)}
\end{array}
Derivation
  1. Initial program 76.5%

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

    \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
  4. Step-by-step derivation
    1. cos-negN/A

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

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

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

    \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
  7. Step-by-step derivation
    1. exp-lowering-exp.f64N/A

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

      \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    3. fabs-subN/A

      \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    4. sub-negN/A

      \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    5. mul-1-negN/A

      \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    6. fabs-lowering-fabs.f64N/A

      \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    7. mul-1-negN/A

      \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    8. sub-negN/A

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

      \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    10. +-commutativeN/A

      \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
    11. accelerator-lowering-fma.f64N/A

      \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
    12. unpow2N/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
    13. *-lowering-*.f64N/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
    14. +-commutativeN/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
    15. +-lowering-+.f64N/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
    16. +-commutativeN/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    17. +-lowering-+.f6485.7

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
  8. Simplified85.7%

    \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \left(n + m\right), \ell\right)}} \]
  9. Final simplification85.7%

    \[\leadsto e^{\left|m - n\right| - \mathsf{fma}\left(0.25, \left(m + n\right) \cdot \left(m + n\right), \ell\right)} \]
  10. Add Preprocessing

Alternative 5: 63.0% accurate, 2.9× speedup?

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

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

\mathbf{elif}\;n \leq 250000:\\
\;\;\;\;e^{0 - \ell}\\

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


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

    1. Initial program 75.0%

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

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    7. Step-by-step derivation
      1. exp-lowering-exp.f64N/A

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

        \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
      3. fabs-subN/A

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      4. sub-negN/A

        \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      5. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      6. fabs-lowering-fabs.f64N/A

        \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      7. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      8. sub-negN/A

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

        \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      10. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      11. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
      12. unpow2N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      13. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      14. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      15. +-lowering-+.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      16. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
      17. +-lowering-+.f6481.7

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    8. Simplified81.7%

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

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

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot \frac{-1}{4}}} \]
      2. *-lowering-*.f64N/A

        \[\leadsto e^{\color{blue}{{m}^{2} \cdot \frac{-1}{4}}} \]
      3. unpow2N/A

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot \frac{-1}{4}} \]
      4. *-lowering-*.f6448.5

        \[\leadsto e^{\color{blue}{\left(m \cdot m\right)} \cdot -0.25} \]
    11. Simplified48.5%

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

    if 3.29999999999999988e-153 < n < 2.5e5

    1. Initial program 81.3%

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

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. cos-lowering-cos.f6496.9

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    7. Step-by-step derivation
      1. exp-lowering-exp.f64N/A

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

        \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
      3. fabs-subN/A

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      4. sub-negN/A

        \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      5. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      6. fabs-lowering-fabs.f64N/A

        \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      7. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      8. sub-negN/A

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

        \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      10. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      11. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
      12. unpow2N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      13. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      14. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      15. +-lowering-+.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      16. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
      17. +-lowering-+.f6478.8

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    8. Simplified78.8%

      \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \left(n + m\right), \ell\right)}} \]
    9. Taylor expanded in l around inf

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    10. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
      2. neg-sub0N/A

        \[\leadsto e^{\color{blue}{0 - \ell}} \]
      3. --lowering--.f6452.6

        \[\leadsto e^{\color{blue}{0 - \ell}} \]
    11. Simplified52.6%

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

    if 2.5e5 < n

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in K around 0

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

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

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    7. Step-by-step derivation
      1. exp-lowering-exp.f64N/A

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

        \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
      3. fabs-subN/A

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      4. sub-negN/A

        \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      5. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      6. fabs-lowering-fabs.f64N/A

        \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      7. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      8. sub-negN/A

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

        \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      10. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      11. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
      12. unpow2N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      13. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      14. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      15. +-lowering-+.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      16. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
      17. +-lowering-+.f6498.5

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    8. Simplified98.5%

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

      \[\leadsto e^{\color{blue}{\frac{-1}{4} \cdot {n}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot \frac{-1}{4}}} \]
      2. unpow2N/A

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
      3. associate-*l*N/A

        \[\leadsto e^{\color{blue}{n \cdot \left(n \cdot \frac{-1}{4}\right)}} \]
      4. *-commutativeN/A

        \[\leadsto e^{n \cdot \color{blue}{\left(\frac{-1}{4} \cdot n\right)}} \]
      5. *-lowering-*.f64N/A

        \[\leadsto e^{\color{blue}{n \cdot \left(\frac{-1}{4} \cdot n\right)}} \]
      6. *-commutativeN/A

        \[\leadsto e^{n \cdot \color{blue}{\left(n \cdot \frac{-1}{4}\right)}} \]
      7. *-lowering-*.f6498.5

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

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

Alternative 6: 69.0% accurate, 2.9× speedup?

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

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

\mathbf{elif}\;n \leq 250000:\\
\;\;\;\;e^{0 - \ell}\\

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


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

    1. Initial program 72.4%

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

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. cos-lowering-cos.f6499.3

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    7. Step-by-step derivation
      1. exp-lowering-exp.f64N/A

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

        \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
      3. fabs-subN/A

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      4. sub-negN/A

        \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      5. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      6. fabs-lowering-fabs.f64N/A

        \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      7. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      8. sub-negN/A

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

        \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      10. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      11. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
      12. unpow2N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      13. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      14. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      15. +-lowering-+.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      16. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
      17. +-lowering-+.f6496.3

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    8. Simplified96.3%

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

      \[\leadsto e^{\color{blue}{\frac{-1}{4} \cdot {n}^{2}}} \]
    10. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto e^{\color{blue}{{n}^{2} \cdot \frac{-1}{4}}} \]
      2. unpow2N/A

        \[\leadsto e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
      3. associate-*l*N/A

        \[\leadsto e^{\color{blue}{n \cdot \left(n \cdot \frac{-1}{4}\right)}} \]
      4. *-commutativeN/A

        \[\leadsto e^{n \cdot \color{blue}{\left(\frac{-1}{4} \cdot n\right)}} \]
      5. *-lowering-*.f64N/A

        \[\leadsto e^{\color{blue}{n \cdot \left(\frac{-1}{4} \cdot n\right)}} \]
      6. *-commutativeN/A

        \[\leadsto e^{n \cdot \color{blue}{\left(n \cdot \frac{-1}{4}\right)}} \]
      7. *-lowering-*.f6497.1

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

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

    if -55 < n < 2.5e5

    1. Initial program 81.0%

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

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
    4. Step-by-step derivation
      1. cos-negN/A

        \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
      2. cos-lowering-cos.f6492.5

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

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

      \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    7. Step-by-step derivation
      1. exp-lowering-exp.f64N/A

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

        \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
      3. fabs-subN/A

        \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      4. sub-negN/A

        \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      5. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      6. fabs-lowering-fabs.f64N/A

        \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      7. mul-1-negN/A

        \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      8. sub-negN/A

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

        \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
      10. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
      11. accelerator-lowering-fma.f64N/A

        \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
      12. unpow2N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      13. *-lowering-*.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
      14. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      15. +-lowering-+.f64N/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
      16. +-commutativeN/A

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
      17. +-lowering-+.f6474.1

        \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    8. Simplified74.1%

      \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \left(n + m\right), \ell\right)}} \]
    9. Taylor expanded in l around inf

      \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
    10. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
      2. neg-sub0N/A

        \[\leadsto e^{\color{blue}{0 - \ell}} \]
      3. --lowering--.f6445.7

        \[\leadsto e^{\color{blue}{0 - \ell}} \]
    11. Simplified45.7%

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

Alternative 7: 34.9% accurate, 3.5× speedup?

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

\\
e^{0 - \ell}
\end{array}
Derivation
  1. Initial program 76.5%

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

    \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \cdot e^{\left(\mathsf{neg}\left({\left(\frac{m + n}{2} - M\right)}^{2}\right)\right) - \left(\ell - \left|m - n\right|\right)} \]
  4. Step-by-step derivation
    1. cos-negN/A

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

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

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

    \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
  7. Step-by-step derivation
    1. exp-lowering-exp.f64N/A

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

      \[\leadsto e^{\color{blue}{\left|m - n\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)}} \]
    3. fabs-subN/A

      \[\leadsto e^{\color{blue}{\left|n - m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    4. sub-negN/A

      \[\leadsto e^{\left|\color{blue}{n + \left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    5. mul-1-negN/A

      \[\leadsto e^{\left|n + \color{blue}{-1 \cdot m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    6. fabs-lowering-fabs.f64N/A

      \[\leadsto e^{\color{blue}{\left|n + -1 \cdot m\right|} - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    7. mul-1-negN/A

      \[\leadsto e^{\left|n + \color{blue}{\left(\mathsf{neg}\left(m\right)\right)}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    8. sub-negN/A

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

      \[\leadsto e^{\left|\color{blue}{n - m}\right| - \left(\ell + \frac{1}{4} \cdot {\left(m + n\right)}^{2}\right)} \]
    10. +-commutativeN/A

      \[\leadsto e^{\left|n - m\right| - \color{blue}{\left(\frac{1}{4} \cdot {\left(m + n\right)}^{2} + \ell\right)}} \]
    11. accelerator-lowering-fma.f64N/A

      \[\leadsto e^{\left|n - m\right| - \color{blue}{\mathsf{fma}\left(\frac{1}{4}, {\left(m + n\right)}^{2}, \ell\right)}} \]
    12. unpow2N/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
    13. *-lowering-*.f64N/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(m + n\right) \cdot \left(m + n\right)}, \ell\right)} \]
    14. +-commutativeN/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
    15. +-lowering-+.f64N/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \color{blue}{\left(n + m\right)} \cdot \left(m + n\right), \ell\right)} \]
    16. +-commutativeN/A

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(\frac{1}{4}, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
    17. +-lowering-+.f6485.7

      \[\leadsto e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \color{blue}{\left(n + m\right)}, \ell\right)} \]
  8. Simplified85.7%

    \[\leadsto \color{blue}{e^{\left|n - m\right| - \mathsf{fma}\left(0.25, \left(n + m\right) \cdot \left(n + m\right), \ell\right)}} \]
  9. Taylor expanded in l around inf

    \[\leadsto e^{\color{blue}{-1 \cdot \ell}} \]
  10. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto e^{\color{blue}{\mathsf{neg}\left(\ell\right)}} \]
    2. neg-sub0N/A

      \[\leadsto e^{\color{blue}{0 - \ell}} \]
    3. --lowering--.f6438.0

      \[\leadsto e^{\color{blue}{0 - \ell}} \]
  11. Simplified38.0%

    \[\leadsto e^{\color{blue}{0 - \ell}} \]
  12. Add Preprocessing

Alternative 8: 6.9% accurate, 359.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 76.5%

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

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

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

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

      \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{\left(n \cdot n\right)} \cdot \frac{-1}{4}} \]
    4. *-lowering-*.f6443.0

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

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

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

      \[\leadsto \color{blue}{\cos \left(\frac{1}{2} \cdot \left(K \cdot m\right) - M\right)} \]
    2. sub-negN/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \left(K \cdot m\right) + \left(\mathsf{neg}\left(M\right)\right)\right)} \]
    3. associate-*r*N/A

      \[\leadsto \cos \left(\color{blue}{\left(\frac{1}{2} \cdot K\right) \cdot m} + \left(\mathsf{neg}\left(M\right)\right)\right) \]
    4. accelerator-lowering-fma.f64N/A

      \[\leadsto \cos \color{blue}{\left(\mathsf{fma}\left(\frac{1}{2} \cdot K, m, \mathsf{neg}\left(M\right)\right)\right)} \]
    5. *-lowering-*.f64N/A

      \[\leadsto \cos \left(\mathsf{fma}\left(\color{blue}{\frac{1}{2} \cdot K}, m, \mathsf{neg}\left(M\right)\right)\right) \]
    6. neg-sub0N/A

      \[\leadsto \cos \left(\mathsf{fma}\left(\frac{1}{2} \cdot K, m, \color{blue}{0 - M}\right)\right) \]
    7. --lowering--.f647.4

      \[\leadsto \cos \left(\mathsf{fma}\left(0.5 \cdot K, m, \color{blue}{0 - M}\right)\right) \]
  8. Simplified7.4%

    \[\leadsto \color{blue}{\cos \left(\mathsf{fma}\left(0.5 \cdot K, m, 0 - M\right)\right)} \]
  9. Taylor expanded in K around 0

    \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(M\right)\right)} \]
  10. Step-by-step derivation
    1. cos-negN/A

      \[\leadsto \color{blue}{\cos M} \]
    2. cos-lowering-cos.f647.7

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified7.7%

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

    \[\leadsto \color{blue}{1} \]
  13. Step-by-step derivation
    1. Simplified7.7%

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

    Reproduce

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