Average Error: 15.3 → 11.1
Time: 8.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} \mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \leq 0.6600767947515078:\\ \;\;\;\;\cos \left(\frac{\sqrt[3]{K \cdot \left(m + n\right)} \cdot \left(\sqrt[3]{K \cdot \left(m + n\right)} \cdot \sqrt[3]{K \cdot \left(m + n\right)}\right)}{2} - M\right) \cdot e^{\left|m - n\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(\left|m - n\right| + \left(m + n\right) \cdot M\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(m \cdot n\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)} + 0.5 \cdot \left(K \cdot \left(\sin M \cdot \left(m \cdot e^{\left(\left|m - n\right| + \left(m + n\right) \cdot M\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(m \cdot n\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)}\right)\right) + e^{\left(\left|m - n\right| + \left(m + n\right) \cdot M\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(m \cdot n\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)} \cdot \left(\sin M \cdot \left(K \cdot n\right)\right)\right)\\ \end{array}\]
\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}
\mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \leq 0.6600767947515078:\\
\;\;\;\;\cos \left(\frac{\sqrt[3]{K \cdot \left(m + n\right)} \cdot \left(\sqrt[3]{K \cdot \left(m + n\right)} \cdot \sqrt[3]{K \cdot \left(m + n\right)}\right)}{2} - M\right) \cdot e^{\left|m - n\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{\left(\left|m - n\right| + \left(m + n\right) \cdot M\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(m \cdot n\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)} + 0.5 \cdot \left(K \cdot \left(\sin M \cdot \left(m \cdot e^{\left(\left|m - n\right| + \left(m + n\right) \cdot M\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(m \cdot n\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)}\right)\right) + e^{\left(\left|m - n\right| + \left(m + n\right) \cdot M\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(m \cdot n\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)} \cdot \left(\sin M \cdot \left(K \cdot n\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
 (if (<=
      (*
       (cos (- (/ (* K (+ m n)) 2.0) M))
       (exp (- (- (fabs (- m n)) l) (pow (- (/ (+ m n) 2.0) M) 2.0))))
      0.6600767947515078)
   (*
    (cos
     (-
      (/
       (* (cbrt (* K (+ m n))) (* (cbrt (* K (+ m n))) (cbrt (* K (+ m n)))))
       2.0)
      M))
    (exp (- (fabs (- m n)) (+ (pow (- (/ (+ m n) 2.0) M) 2.0) l))))
   (+
    (*
     (cos M)
     (exp
      (-
       (+ (fabs (- m n)) (* (+ m n) M))
       (+ (+ (* M M) (+ l (* 0.5 (* m n)))) (* 0.25 (+ (* n n) (* m m)))))))
    (*
     0.5
     (+
      (*
       K
       (*
        (sin M)
        (*
         m
         (exp
          (-
           (+ (fabs (- m n)) (* (+ m n) M))
           (+
            (+ (* M M) (+ l (* 0.5 (* m n))))
            (* 0.25 (+ (* n n) (* m m)))))))))
      (*
       (exp
        (-
         (+ (fabs (- m n)) (* (+ m n) M))
         (+ (+ (* M M) (+ l (* 0.5 (* m n)))) (* 0.25 (+ (* n n) (* m m))))))
       (* (sin M) (* K 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)));
}
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if ((cos(((K * (m + n)) / 2.0) - M) * exp((fabs(m - n) - l) - pow((((m + n) / 2.0) - M), 2.0))) <= 0.6600767947515078) {
		tmp = cos(((cbrt(K * (m + n)) * (cbrt(K * (m + n)) * cbrt(K * (m + n)))) / 2.0) - M) * exp(fabs(m - n) - (pow((((m + n) / 2.0) - M), 2.0) + l));
	} else {
		tmp = (cos(M) * exp((fabs(m - n) + ((m + n) * M)) - (((M * M) + (l + (0.5 * (m * n)))) + (0.25 * ((n * n) + (m * m)))))) + (0.5 * ((K * (sin(M) * (m * exp((fabs(m - n) + ((m + n) * M)) - (((M * M) + (l + (0.5 * (m * n)))) + (0.25 * ((n * n) + (m * m)))))))) + (exp((fabs(m - n) + ((m + n) * M)) - (((M * M) + (l + (0.5 * (m * n)))) + (0.25 * ((n * n) + (m * m))))) * (sin(M) * (K * n)))));
	}
	return tmp;
}

Error

Bits error versus K

Bits error versus m

Bits error versus n

Bits error versus M

Bits error versus l

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)) (-.f64 l (fabs.f64 (-.f64 m n)))))) < 0.66007679475150782

    1. Initial program 1.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. Simplified1.1

      \[\leadsto \color{blue}{\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\left|m - n\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt_binary64_7951.1

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

    if 0.66007679475150782 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)) (-.f64 l (fabs.f64 (-.f64 m n))))))

    1. Initial program 53.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. Simplified53.2

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

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

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

      \[\leadsto \color{blue}{e^{\left(\left|m - n\right| + \left(m \cdot M + M \cdot n\right)\right) - \left(0.25 \cdot {n}^{2} + \left(0.25 \cdot {m}^{2} + \left({M}^{2} + \left(0.5 \cdot \left(m \cdot n\right) + \ell\right)\right)\right)\right)} \cdot \cos \left(-M\right) - \left(0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(e^{\left(\left|m - n\right| + \left(m \cdot M + M \cdot n\right)\right) - \left(0.25 \cdot {n}^{2} + \left(0.25 \cdot {m}^{2} + \left({M}^{2} + \left(0.5 \cdot \left(m \cdot n\right) + \ell\right)\right)\right)\right)} \cdot m\right)\right)\right) + 0.5 \cdot \left(e^{\left(\left|m - n\right| + \left(m \cdot M + M \cdot n\right)\right) - \left(0.25 \cdot {n}^{2} + \left(0.25 \cdot {m}^{2} + \left({M}^{2} + \left(0.5 \cdot \left(m \cdot n\right) + \ell\right)\right)\right)\right)} \cdot \left(K \cdot \left(n \cdot \sin \left(-M\right)\right)\right)\right)\right)}\]
    6. Simplified37.7

      \[\leadsto \color{blue}{\cos M \cdot e^{\left(\left|m - n\right| + M \cdot \left(n + m\right)\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(n \cdot m\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)} - 0.5 \cdot \left(K \cdot \left(\left(-\sin M\right) \cdot \left(m \cdot e^{\left(\left|m - n\right| + M \cdot \left(n + m\right)\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(n \cdot m\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)}\right)\right) + \left(\left(K \cdot n\right) \cdot \left(-\sin M\right)\right) \cdot e^{\left(\left|m - n\right| + M \cdot \left(n + m\right)\right) - \left(\left(M \cdot M + \left(\ell + 0.5 \cdot \left(n \cdot m\right)\right)\right) + 0.25 \cdot \left(n \cdot n + m \cdot m\right)\right)}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification11.1

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

Reproduce

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