Average Error: 15.4 → 1.4
Time: 17.9s
Precision: binary64
Cost: 20672
\[\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 := \left(m + n\right) \cdot 0.5 - M\\ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - t_0 \cdot t_0} \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 (- (* (+ m n) 0.5) M)))
   (* (cos M) (exp (- (- (fabs (- m n)) l) (* t_0 t_0))))))
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 = ((m + n) * 0.5) - M;
	return cos(M) * exp(((fabs((m - n)) - l) - (t_0 * t_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((((k * (m + n)) / 2.0d0) - m_1)) * exp((-((((m + n) / 2.0d0) - m_1) ** 2.0d0) - (l - abs((m - n)))))
end function
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
    t_0 = ((m + n) * 0.5d0) - m_1
    code = cos(m_1) * exp(((abs((m - n)) - l) - (t_0 * t_0)))
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)))));
}
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = ((m + n) * 0.5) - M;
	return Math.cos(M) * Math.exp(((Math.abs((m - n)) - l) - (t_0 * t_0)));
}
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)))))
def code(K, m, n, M, l):
	t_0 = ((m + n) * 0.5) - M
	return math.cos(M) * math.exp(((math.fabs((m - n)) - l) - (t_0 * t_0)))
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(Float64(Float64(m + n) * 0.5) - M)
	return Float64(cos(M) * exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(t_0 * t_0))))
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
function tmp = code(K, m, n, M, l)
	t_0 = ((m + n) * 0.5) - M;
	tmp = cos(M) * exp(((abs((m - n)) - l) - (t_0 * t_0)));
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[(N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision] - M), $MachinePrecision]}, N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(t$95$0 * t$95$0), $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 := \left(m + n\right) \cdot 0.5 - M\\
\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - t_0 \cdot t_0}
\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}} \]
    Proof
    (*.f64 (cos.f64 (-.f64 (*.f64 (+.f64 m n) (/.f64 K 2)) M)) (exp.f64 (-.f64 (-.f64 (fabs.f64 (-.f64 m n)) l) (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (cos.f64 (-.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (+.f64 m n) K) 2)) M)) (exp.f64 (-.f64 (-.f64 (fabs.f64 (-.f64 m n)) l) (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (cos.f64 (-.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 K (+.f64 m n))) 2) M)) (exp.f64 (-.f64 (-.f64 (fabs.f64 (-.f64 m n)) l) (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (Rewrite=> associate--l-_binary64 (-.f64 (fabs.f64 (-.f64 m n)) (+.f64 l (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (-.f64 (fabs.f64 (-.f64 m n)) (Rewrite<= +-commutative_binary64 (+.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2) l))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (Rewrite=> associate--r+_binary64 (-.f64 (-.f64 (fabs.f64 (-.f64 m n)) (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)) l)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (-.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (fabs.f64 (-.f64 m n)) (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)))) l))): 0 points increase in error, 0 points decrease in error
    (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (Rewrite<= associate-+r-_binary64 (+.f64 (fabs.f64 (-.f64 m n)) (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)) l))))): 10 points increase in error, 0 points decrease in error
    (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (Rewrite<= +-commutative_binary64 (+.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)) l) (fabs.f64 (-.f64 m n)))))): 0 points increase in error, 10 points decrease in error
    (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) 2) M)) (exp.f64 (Rewrite<= associate--r-_binary64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)) (-.f64 l (fabs.f64 (-.f64 m n))))))): 0 points increase in error, 0 points decrease in error
  3. Taylor expanded in K around 0 1.4

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

    \[\leadsto \color{blue}{\cos M} \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
    Proof
    (*.f64 (cos.f64 M) (exp.f64 (-.f64 (-.f64 (fabs.f64 (-.f64 m n)) l) (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (Rewrite<= cos-neg_binary64 (cos.f64 (neg.f64 M))) (exp.f64 (-.f64 (-.f64 (fabs.f64 (-.f64 m n)) l) (pow.f64 (-.f64 (/.f64 (+.f64 m n) 2) M) 2)))): 0 points increase in error, 0 points decrease in error
  5. Applied egg-rr1.4

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

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

Alternatives

Alternative 1
Error8.0
Cost20676
\[\begin{array}{l} \mathbf{if}\;m \leq -2 \cdot 10^{+22}:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) + \left(m + \left(n \cdot 0.5 - M\right)\right) \cdot \left(M - n \cdot 0.5\right)}\\ \end{array} \]
Alternative 2
Error7.1
Cost20548
\[\begin{array}{l} t_0 := n \cdot 0.5 - M\\ \mathbf{if}\;m \leq -2 \cdot 10^{+22}:\\ \;\;\;\;\cos M \cdot e^{m}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - t_0 \cdot t_0}\\ \end{array} \]
Alternative 3
Error16.6
Cost13504
\[\cos M \cdot e^{m - \left(\left(n + \ell\right) + M \cdot M\right)} \]
Alternative 4
Error13.9
Cost13449
\[\begin{array}{l} \mathbf{if}\;M \leq -2.8 \cdot 10^{+30} \lor \neg \left(M \leq 0.061\right):\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{m - \left(n + \ell\right)}\\ \end{array} \]
Alternative 5
Error28.4
Cost13188
\[\begin{array}{l} \mathbf{if}\;n \leq 1000:\\ \;\;\;\;e^{m - \left(n + \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-n}\\ \end{array} \]
Alternative 6
Error31.3
Cost6720
\[e^{m - \left(n + \ell\right)} \]
Alternative 7
Error59.6
Cost6464
\[\cos M \]

Error

Reproduce

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