Maksimov and Kolovsky, Equation (32)

?

Percentage Accurate: 75.9% → 96.7%
Time: 19.0s
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|n - m\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)} \]
(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 (- n m)) (+ (pow (- (/ (+ m n) 2.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) {
	return cos(M) * exp((fabs((n - m)) - (pow((((m + n) / 2.0) - M), 2.0) + l)));
}
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((n - m)) - (((((m + n) / 2.0d0) - m_1) ** 2.0d0) + l)))
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((n - m)) - (Math.pow((((m + n) / 2.0) - M), 2.0) + l)));
}
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((n - m)) - (math.pow((((m + n) / 2.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)
	return Float64(cos(M) * exp(Float64(abs(Float64(n - m)) - Float64((Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0) + l))))
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((n - m)) - (((((m + n) / 2.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_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - N[(N[Power[N[(N[(N[(m + n), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision] + l), $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|n - m\right| - \left({\left(\frac{m + n}{2} - M\right)}^{2} + \ell\right)}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 11 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 75.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. Simplified75.4%

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

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

    associate-/l* [=>]75.4

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

    associate--r- [=>]75.4

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

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

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

    [Start]97.3

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

    cos-neg [=>]97.3

    \[ \color{blue}{\cos M} \cdot e^{\left(\left(-{\left(\frac{m + n}{2} - M\right)}^{2}\right) - \ell\right) + \left|m - n\right|} \]
  5. Final simplification97.3%

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

Alternatives

Alternative 1
Accuracy67.2%
Cost20944
\[\begin{array}{l} t_0 := \frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{e^{M \cdot M + \left(\ell - \left|n - m\right|\right)}}\\ t_1 := \cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{if}\;n \leq -1.8 \cdot 10^{-293}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 1.45 \cdot 10^{-174}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 6.6 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 55:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]
Alternative 2
Accuracy67.1%
Cost20944
\[\begin{array}{l} t_0 := \cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ t_1 := \left|n - m\right|\\ \mathbf{if}\;n \leq -1.2 \cdot 10^{-293}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 4.8 \cdot 10^{-172}:\\ \;\;\;\;\cos \left(\frac{K}{\frac{2}{m + n}} - M\right) \cdot e^{t_1 - \left(\ell + M \cdot M\right)}\\ \mathbf{elif}\;n \leq 2.6 \cdot 10^{-154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 55:\\ \;\;\;\;\frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{e^{M \cdot M + \left(\ell - t_1\right)}}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]
Alternative 3
Accuracy64.2%
Cost14032
\[\begin{array}{l} t_0 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ t_1 := \cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{if}\;n \leq -6.8 \cdot 10^{-292}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 2.6 \cdot 10^{-188}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 2.1 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 9.2 \cdot 10^{-53}:\\ \;\;\;\;\frac{\cos \left(\frac{m + n}{2} \cdot K - M\right)}{e^{\ell}}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]
Alternative 4
Accuracy64.1%
Cost13844
\[\begin{array}{l} t_0 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ t_1 := \cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{if}\;n \leq -3.5 \cdot 10^{-292}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 1.05 \cdot 10^{-191}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 1.28 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 7.4 \cdot 10^{-56}:\\ \;\;\;\;e^{-\ell}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]
Alternative 5
Accuracy64.3%
Cost13844
\[\begin{array}{l} t_0 := \cos M \cdot e^{M \cdot \left(-M\right)}\\ t_1 := \cos M \cdot e^{m \cdot \left(m \cdot -0.25\right)}\\ \mathbf{if}\;n \leq -1.15 \cdot 10^{-294}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 1.4 \cdot 10^{-181}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 3.9 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 4.6 \cdot 10^{-56}:\\ \;\;\;\;\frac{\cos \left(m \cdot \left(K \cdot 0.5\right)\right)}{e^{\ell}}\\ \mathbf{elif}\;n \leq 54:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]
Alternative 6
Accuracy77.1%
Cost13449
\[\begin{array}{l} \mathbf{if}\;M \leq -26.5 \lor \neg \left(M \leq 27\right):\\ \;\;\;\;\cos M \cdot e^{M \cdot \left(-M\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \end{array} \]
Alternative 7
Accuracy72.0%
Cost13320
\[\begin{array}{l} \mathbf{if}\;\ell \leq -7.2 \cdot 10^{+34}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{elif}\;\ell \leq 0.215:\\ \;\;\;\;{\left(e^{n}\right)}^{\left(n \cdot -0.25\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
Alternative 8
Accuracy49.0%
Cost13124
\[\begin{array}{l} \mathbf{if}\;\ell \leq 8 \cdot 10^{-6}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;e^{-\ell}\\ \end{array} \]
Alternative 9
Accuracy49.0%
Cost13124
\[\begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{-159}:\\ \;\;\;\;\cos M \cdot e^{\ell}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \end{array} \]
Alternative 10
Accuracy35.0%
Cost6528
\[e^{-\ell} \]

Reproduce?

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