Average Error: 15.4 → 1.3
Time: 11.4s
Precision: binary64
\[\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)} \]
\[\begin{array}{l} t_0 := 0.5 \cdot \left(n + m\right)\\ \log \left({\left(\mathsf{expm1}\left(\log \left(1 + e^{\cos \left(\mathsf{fma}\left(K, t_0, -M\right)\right)}\right)\right)\right)}^{\left(e^{\left|n - m\right| - \left({\left(t_0 - M\right)}^{2} + \ell\right)}\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)))))))
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (* 0.5 (+ n m))))
   (log
    (pow
     (expm1 (log (+ 1.0 (exp (cos (fma K t_0 (- M)))))))
     (exp (- (fabs (- n m)) (+ (pow (- t_0 M) 2.0) l)))))))
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)))));
}
double code(double K, double m, double n, double M, double l) {
	double t_0 = 0.5 * (n + m);
	return log(pow(expm1(log((1.0 + exp(cos(fma(K, t_0, -M)))))), exp((fabs((n - m)) - (pow((t_0 - M), 2.0) + l)))));
}
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 code(K, m, n, M, l)
	t_0 = Float64(0.5 * Float64(n + m))
	return log((expm1(log(Float64(1.0 + exp(cos(fma(K, t_0, Float64(-M))))))) ^ exp(Float64(abs(Float64(n - m)) - Float64((Float64(t_0 - M) ^ 2.0) + l)))))
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]
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(0.5 * N[(n + m), $MachinePrecision]), $MachinePrecision]}, N[Log[N[Power[N[(Exp[N[Log[N[(1.0 + N[Exp[N[Cos[N[(K * t$95$0 + (-M)), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision], N[Exp[N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - N[(N[Power[N[(t$95$0 - M), $MachinePrecision], 2.0], $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]]
\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)}
\begin{array}{l}
t_0 := 0.5 \cdot \left(n + m\right)\\
\log \left({\left(\mathsf{expm1}\left(\log \left(1 + e^{\cos \left(\mathsf{fma}\left(K, t_0, -M\right)\right)}\right)\right)\right)}^{\left(e^{\left|n - m\right| - \left({\left(t_0 - M\right)}^{2} + \ell\right)}\right)}\right)
\end{array}

Error

Bits error versus K

Bits error versus m

Bits error versus n

Bits error versus M

Bits error versus l

Derivation

  1. Initial program 15.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. Simplified15.4

    \[\leadsto \color{blue}{\cos \left(\mathsf{fma}\left(K, \frac{m + n}{2}, -M\right)\right) \cdot e^{\left|n - m\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}} \]
  3. Applied egg-rr1.3

    \[\leadsto \color{blue}{\log \left({\left(e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, -M\right)\right)}\right)}^{\left(e^{\left|n - m\right| - \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} + \ell\right)}\right)}\right)} \]
  4. Applied egg-rr1.3

    \[\leadsto \log \left({\color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\cos \left(\mathsf{fma}\left(K, \left(m + n\right) \cdot 0.5, -M\right)\right)}\right)\right)\right)}}^{\left(e^{\left|n - m\right| - \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} + \ell\right)}\right)}\right) \]
  5. Taylor expanded in K around inf 1.3

    \[\leadsto \log \left({\left(\mathsf{expm1}\left(\color{blue}{\log \left(1 + e^{\cos \left(\mathsf{fma}\left(K, 0.5 \cdot \left(n + m\right), -M\right)\right)}\right)}\right)\right)}^{\left(e^{\left|n - m\right| - \left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} + \ell\right)}\right)}\right) \]
  6. Final simplification1.3

    \[\leadsto \log \left({\left(\mathsf{expm1}\left(\log \left(1 + e^{\cos \left(\mathsf{fma}\left(K, 0.5 \cdot \left(n + m\right), -M\right)\right)}\right)\right)\right)}^{\left(e^{\left|n - m\right| - \left({\left(0.5 \cdot \left(n + m\right) - M\right)}^{2} + \ell\right)}\right)}\right) \]

Reproduce

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