Average Error: 15.3 → 1.3
Time: 18.5s
Precision: binary64
Cost: 26624
\[\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)} \]
\[\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
(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
 (* (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((((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(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((((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
    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((((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) {
	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((((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):
	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(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)
	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((((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)
	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[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_] := 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]
\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)}
\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 15.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. Taylor expanded in K around 0 1.3

    \[\leadsto \color{blue}{\cos \left(-M\right)} \cdot e^{\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \left(\ell - \left|m - n\right|\right)} \]
  3. Simplified1.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)} \]
    Proof
    (cos.f64 M): 0 points increase in error, 0 points decrease in error
    (Rewrite<= cos-neg_binary64 (cos.f64 (neg.f64 M))): 0 points increase in error, 0 points decrease in error
  4. Final simplification1.3

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

Alternatives

Alternative 1
Error17.2
Cost20680
\[\begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := \cos M \cdot e^{n \cdot \left(n \cdot -0.25\right) + t_0}\\ t_2 := e^{t_0 - M \cdot M}\\ \mathbf{if}\;m \leq -3542.8694422253243:\\ \;\;\;\;{\left(e^{-0.25}\right)}^{\left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -4.654717399764785 \cdot 10^{-49}:\\ \;\;\;\;\cos \left(\frac{\left(m + n\right) \cdot K}{2} - M\right) \cdot t_2\\ \mathbf{elif}\;m \leq -1.320442165405721 \cdot 10^{-147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;m \leq -2.5406921774726805 \cdot 10^{-224}:\\ \;\;\;\;\cos M \cdot t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error19.1
Cost20432
\[\begin{array}{l} t_0 := \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - M \cdot M}\\ t_1 := \cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ \mathbf{if}\;m \leq -892647643.7989799:\\ \;\;\;\;{\left(e^{-0.25}\right)}^{\left(m \cdot m\right)}\\ \mathbf{elif}\;m \leq -5.81673436329416 \cdot 10^{-114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;m \leq -1.320442165405721 \cdot 10^{-147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;m \leq 3.7360145713079466 \cdot 10^{-302}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error17.3
Cost20432
\[\begin{array}{l} t_0 := \left|m - n\right| - \ell\\ t_1 := \cos M \cdot e^{m \cdot \left(m \cdot -0.25\right) + t_0}\\ \mathbf{if}\;n \leq 3.4857314303992644 \cdot 10^{-159}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 6.201069336706437 \cdot 10^{-105}:\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{elif}\;n \leq 1.471505941867912 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 10.378332686525118:\\ \;\;\;\;\cos M \cdot e^{t_0 - M \cdot M}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ \end{array} \]
Alternative 4
Error14.0
Cost14296
\[\begin{array}{l} t_0 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ t_1 := \cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ t_2 := e^{m - \ell} \cdot \cos \left(0.5 \cdot \left(m \cdot K\right) - M\right)\\ \mathbf{if}\;M \leq -6.42167983841773 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq -6.777779732312039 \cdot 10^{-259}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;M \leq 1.5061572799715848 \cdot 10^{-219}:\\ \;\;\;\;{\left(e^{-0.25}\right)}^{\left(m \cdot m\right)}\\ \mathbf{elif}\;M \leq 2.6389368189511725 \cdot 10^{-110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;M \leq 3.4 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;M \leq 0.0003010648100509361:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error14.3
Cost14164
\[\begin{array}{l} t_0 := e^{m - \ell} \cdot \cos \left(0.5 \cdot \left(m \cdot K\right) - M\right)\\ t_1 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ t_2 := n \cdot \left(n \cdot -0.25\right)\\ \mathbf{if}\;M \leq -6.42167983841773 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;M \leq 4.355790771290999 \cdot 10^{-250}:\\ \;\;\;\;\cos \left(K \cdot \left(n \cdot 0.5\right) - M\right) \cdot e^{t_2 - \left(n + \ell\right)}\\ \mathbf{elif}\;M \leq 2.6389368189511725 \cdot 10^{-110}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq 3.4 \cdot 10^{-72}:\\ \;\;\;\;\cos M \cdot e^{t_2}\\ \mathbf{elif}\;M \leq 0.0003010648100509361:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error12.4
Cost13844
\[\begin{array}{l} t_0 := \cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ t_1 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ t_2 := {\left(e^{-0.25}\right)}^{\left(m \cdot m\right)}\\ \mathbf{if}\;M \leq -6.42167983841773 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;M \leq -6.777779732312039 \cdot 10^{-259}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq 2.6389368189511725 \cdot 10^{-110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;M \leq 2.0750739643249868 \cdot 10^{-73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq 0.0003010648100509361:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error12.4
Cost13844
\[\begin{array}{l} t_0 := \cos M \cdot e^{n \cdot \left(n \cdot -0.25\right)}\\ t_1 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -6.42167983841773 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;M \leq -6.777779732312039 \cdot 10^{-259}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq 2.6389368189511725 \cdot 10^{-110}:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{elif}\;M \leq 2.0750739643249868 \cdot 10^{-73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq 0.0003010648100509361:\\ \;\;\;\;{\left(e^{-0.25}\right)}^{\left(m \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error12.8
Cost13712
\[\begin{array}{l} t_0 := {\left(e^{-0.25}\right)}^{\left(m \cdot m\right)}\\ t_1 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{if}\;M \leq -2452.678531624007:\\ \;\;\;\;t_1\\ \mathbf{elif}\;M \leq -2.548460697738092 \cdot 10^{-190}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;M \leq -1.3994022153086016 \cdot 10^{-253}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{elif}\;M \leq 0.0003010648100509361:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error19.1
Cost13188
\[\begin{array}{l} \mathbf{if}\;\ell \leq 3.946747512637699 \cdot 10^{-7}:\\ \;\;\;\;{\left(e^{-0.25}\right)}^{\left(m \cdot m\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
Alternative 10
Error43.4
Cost12992
\[\frac{\cos M}{e^{\ell}} \]
Alternative 11
Error43.4
Cost6528
\[e^{-\ell} \]
Alternative 12
Error59.6
Cost6464
\[\cos M \]

Error

Reproduce

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