?

Average Error: 15.6 → 1.8
Time: 15.2s
Precision: binary64
Cost: 13636

?

\[ \begin{array}{c}[m, n] = \mathsf{sort}([m, n])\\ \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}\;\ell \leq -1 \cdot 10^{+144}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\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 (<= l -1e+144)
   (* (cos M) (exp l))
   (* (cos M) (exp (- (- m n) (+ l (* M M)))))))
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 (l <= -1e+144) {
		tmp = cos(M) * exp(l);
	} else {
		tmp = cos(M) * exp(((m - n) - (l + (M * M))));
	}
	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
    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) :: tmp
    if (l <= (-1d+144)) then
        tmp = cos(m_1) * exp(l)
    else
        tmp = cos(m_1) * exp(((m - n) - (l + (m_1 * m_1))))
    end if
    code = tmp
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 tmp;
	if (l <= -1e+144) {
		tmp = Math.cos(M) * Math.exp(l);
	} else {
		tmp = Math.cos(M) * Math.exp(((m - n) - (l + (M * M))));
	}
	return tmp;
}
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):
	tmp = 0
	if l <= -1e+144:
		tmp = math.cos(M) * math.exp(l)
	else:
		tmp = math.cos(M) * math.exp(((m - n) - (l + (M * M))))
	return tmp
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)
	tmp = 0.0
	if (l <= -1e+144)
		tmp = Float64(cos(M) * exp(l));
	else
		tmp = Float64(cos(M) * exp(Float64(Float64(m - n) - Float64(l + Float64(M * M)))));
	end
	return tmp
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_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (l <= -1e+144)
		tmp = cos(M) * exp(l);
	else
		tmp = cos(M) * exp(((m - n) - (l + (M * M))));
	end
	tmp_2 = tmp;
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_] := If[LessEqual[l, -1e+144], N[(N[Cos[M], $MachinePrecision] * N[Exp[l], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(m - n), $MachinePrecision] - N[(l + N[(M * M), $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}
\mathbf{if}\;\ell \leq -1 \cdot 10^{+144}:\\
\;\;\;\;\cos M \cdot e^{\ell}\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if l < -1.00000000000000002e144

    1. Initial program 17.9

      \[\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. Simplified17.9

      \[\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

      [Start]17.9

      \[ \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)} \]

      *-commutative [=>]17.9

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

      associate-*r/ [<=]17.9

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

      associate--r- [=>]17.9

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

      +-commutative [=>]17.9

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

      sub-neg [=>]17.9

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

      distribute-neg-out [=>]17.9

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

      sub-neg [<=]17.9

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

      +-commutative [=>]17.9

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

      associate--l- [<=]17.9

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

      \[\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. Simplified0

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

      [Start]0

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

      cos-neg [=>]0

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

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{0.25 \cdot {m}^{2}}} \]
    6. Simplified35.6

      \[\leadsto \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(m \cdot m\right) \cdot 0.25}} \]
      Proof

      [Start]35.6

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

      *-commutative [=>]35.6

      \[ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{{m}^{2} \cdot 0.25}} \]

      unpow2 [=>]35.6

      \[ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{\left(m \cdot m\right)} \cdot 0.25} \]
    7. Taylor expanded in l around inf 64.0

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot \ell}} \]
    8. Simplified64.0

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

      [Start]64.0

      \[ \cos M \cdot e^{-1 \cdot \ell} \]

      mul-1-neg [=>]64.0

      \[ \cos M \cdot e^{\color{blue}{-\ell}} \]
    9. Applied egg-rr0

      \[\leadsto \color{blue}{\left(1 + \cos M \cdot e^{\ell}\right) - 1} \]
    10. Simplified0

      \[\leadsto \color{blue}{\cos M \cdot e^{\ell}} \]
      Proof

      [Start]0

      \[ \left(1 + \cos M \cdot e^{\ell}\right) - 1 \]

      +-commutative [=>]0

      \[ \color{blue}{\left(\cos M \cdot e^{\ell} + 1\right)} - 1 \]

      associate--l+ [=>]0

      \[ \color{blue}{\cos M \cdot e^{\ell} + \left(1 - 1\right)} \]

      metadata-eval [=>]0

      \[ \cos M \cdot e^{\ell} + \color{blue}{0} \]

      +-rgt-identity [=>]0

      \[ \color{blue}{\cos M \cdot e^{\ell}} \]

    if -1.00000000000000002e144 < l

    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

      [Start]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)} \]

      *-commutative [=>]15.4

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

      associate-*r/ [<=]15.4

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

      associate--r- [=>]15.4

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

      +-commutative [=>]15.4

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

      sub-neg [=>]15.4

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

      distribute-neg-out [=>]15.4

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

      sub-neg [<=]15.4

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

      +-commutative [=>]15.4

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

      associate--l- [<=]15.4

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

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

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

      [Start]34.4

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

      unpow2 [=>]34.4

      \[ \cos \left(\left(m + n\right) \cdot \frac{K}{2} - M\right) \cdot e^{\left(\left|m - n\right| - \ell\right) - \color{blue}{M \cdot M}} \]
    5. Applied egg-rr15.8

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\right)} - 1} \]
    6. Simplified15.8

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

      [Start]15.8

      \[ e^{\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\right)} - 1 \]

      expm1-def [=>]15.8

      \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \left(\left(m + n\right) \cdot \left(K \cdot 0.5\right) - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\right)\right)} \]

      expm1-log1p [=>]15.8

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

      +-commutative [=>]15.8

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

      associate-*r* [=>]15.8

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

      *-commutative [<=]15.8

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

      *-commutative [<=]15.8

      \[ \cos \left(\color{blue}{0.5 \cdot \left(K \cdot \left(n + m\right)\right)} - M\right) \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]
    7. Taylor expanded in K around 0 1.9

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

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

      [Start]1.9

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

      cos-neg [=>]1.9

      \[ \color{blue}{\cos M} \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{+144}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{\left(m - n\right) - \left(\ell + M \cdot M\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error1.3
Cost26624
\[\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \]
Alternative 2
Error14.2
Cost13512
\[\begin{array}{l} \mathbf{if}\;\ell \leq -8.2 \cdot 10^{-5}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq 0.114:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
Alternative 3
Error14.1
Cost13512
\[\begin{array}{l} \mathbf{if}\;\ell \leq -8.2 \cdot 10^{-5}:\\ \;\;\;\;1 + \left(\cos M \cdot e^{\ell} + -1\right)\\ \mathbf{elif}\;\ell \leq 0.114:\\ \;\;\;\;\cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
Alternative 4
Error30.9
Cost13188
\[\begin{array}{l} \mathbf{if}\;\ell \leq 5 \cdot 10^{-136}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-\ell}\\ \end{array} \]
Alternative 5
Error30.9
Cost13124
\[\begin{array}{l} \mathbf{if}\;\ell \leq 1.4 \cdot 10^{-16}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
Alternative 6
Error43.8
Cost6528
\[e^{-\ell} \]
Alternative 7
Error59.5
Cost6464
\[\cos M \]

Error

Reproduce?

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