Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.7% → 96.6%
Time: 53.0s
Alternatives: 4
Speedup: 1.4×

Specification

?
\[\begin{array}{l} \\ \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)} \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)))))))
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)))));
}
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
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)))));
}
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)))))
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 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
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]
\begin{array}{l}

\\
\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)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 75.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \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)} \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)))))))
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)))));
}
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
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)))));
}
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)))))
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 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
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]
\begin{array}{l}

\\
\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)}
\end{array}

Alternative 1: 96.6% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(m + n\right) \cdot 0.5 - M\\ \cos M \cdot e^{\left|n - m\right| - \left(t\_0 \cdot t\_0 + \ell\right)} \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (- (* (+ m n) 0.5) M)))
   (* (cos M) (exp (- (fabs (- n m)) (+ (* t_0 t_0) l))))))
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((n - m)) - ((t_0 * t_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
    real(8) :: t_0
    t_0 = ((m + n) * 0.5d0) - m_1
    code = cos(m_1) * exp((abs((n - m)) - ((t_0 * t_0) + l)))
end function
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((n - m)) - ((t_0 * t_0) + l)));
}
def code(K, m, n, M, l):
	t_0 = ((m + n) * 0.5) - M
	return math.cos(M) * math.exp((math.fabs((n - m)) - ((t_0 * t_0) + l)))
function code(K, m, n, M, l)
	t_0 = Float64(Float64(Float64(m + n) * 0.5) - M)
	return Float64(cos(M) * exp(Float64(abs(Float64(n - m)) - Float64(Float64(t_0 * t_0) + l))))
end
function tmp = code(K, m, n, M, l)
	t_0 = ((m + n) * 0.5) - M;
	tmp = cos(M) * exp((abs((n - m)) - ((t_0 * t_0) + l)));
end
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[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision] - N[(N[(t$95$0 * t$95$0), $MachinePrecision] + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5 - M\\
\cos M \cdot e^{\left|n - m\right| - \left(t\_0 \cdot t\_0 + \ell\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 73.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. Add Preprocessing
  3. Taylor expanded in K around 0 96.1%

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
    2. sub-neg96.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|m - n\right| + \left(-\left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)\right)}} \]
    3. sub-neg96.1%

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

      \[\leadsto \cos M \cdot e^{\left|m - n\right| + \left(-\left(\ell + {\color{blue}{\left(\left(-M\right) + 0.5 \cdot \left(m + n\right)\right)}}^{2}\right)\right)} \]
    5. neg-mul-196.1%

      \[\leadsto \cos M \cdot e^{\left|m - n\right| + \left(-\left(\ell + {\left(\color{blue}{-1 \cdot M} + 0.5 \cdot \left(m + n\right)\right)}^{2}\right)\right)} \]
    6. sub-neg96.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|m - n\right| - \left(\ell + {\left(-1 \cdot M + 0.5 \cdot \left(m + n\right)\right)}^{2}\right)}} \]
  5. Simplified96.1%

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

      \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \color{blue}{\left(\left(m + n\right) \cdot 0.5 - M\right) \cdot \left(\left(m + n\right) \cdot 0.5 - M\right)}\right)} \]
  7. Applied egg-rr96.1%

    \[\leadsto \cos M \cdot e^{\left|m - n\right| - \left(\ell + \color{blue}{\left(\left(m + n\right) \cdot 0.5 - M\right) \cdot \left(\left(m + n\right) \cdot 0.5 - M\right)}\right)} \]
  8. Final simplification96.1%

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

Alternative 2: 33.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;n \leq 14.5:\\ \;\;\;\;e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{n - 0.25 \cdot {m}^{2}}}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (if (<= n 14.5)
   (exp (- (pow (- (* n 0.5) M) 2.0) (+ n l)))
   (/ (cos M) (exp (- n (* 0.25 (pow m 2.0)))))))
double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 14.5) {
		tmp = exp((pow(((n * 0.5) - M), 2.0) - (n + l)));
	} else {
		tmp = cos(M) / exp((n - (0.25 * pow(m, 2.0))));
	}
	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
    real(8) :: tmp
    if (n <= 14.5d0) then
        tmp = exp(((((n * 0.5d0) - m_1) ** 2.0d0) - (n + l)))
    else
        tmp = cos(m_1) / exp((n - (0.25d0 * (m ** 2.0d0))))
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double tmp;
	if (n <= 14.5) {
		tmp = Math.exp((Math.pow(((n * 0.5) - M), 2.0) - (n + l)));
	} else {
		tmp = Math.cos(M) / Math.exp((n - (0.25 * Math.pow(m, 2.0))));
	}
	return tmp;
}
def code(K, m, n, M, l):
	tmp = 0
	if n <= 14.5:
		tmp = math.exp((math.pow(((n * 0.5) - M), 2.0) - (n + l)))
	else:
		tmp = math.cos(M) / math.exp((n - (0.25 * math.pow(m, 2.0))))
	return tmp
function code(K, m, n, M, l)
	tmp = 0.0
	if (n <= 14.5)
		tmp = exp(Float64((Float64(Float64(n * 0.5) - M) ^ 2.0) - Float64(n + l)));
	else
		tmp = Float64(cos(M) / exp(Float64(n - Float64(0.25 * (m ^ 2.0)))));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	tmp = 0.0;
	if (n <= 14.5)
		tmp = exp(((((n * 0.5) - M) ^ 2.0) - (n + l)));
	else
		tmp = cos(M) / exp((n - (0.25 * (m ^ 2.0))));
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := If[LessEqual[n, 14.5], N[Exp[N[(N[Power[N[(N[(n * 0.5), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision] - N[(n + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(n - N[(0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;n \leq 14.5:\\
\;\;\;\;e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\cos M}{e^{n - 0.25 \cdot {m}^{2}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if n < 14.5

    1. Initial program 74.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. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt74.2%

        \[\leadsto \color{blue}{\left(\sqrt[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)}} \cdot \sqrt[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)}}\right) \cdot \sqrt[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. pow374.3%

        \[\leadsto \color{blue}{{\left(\sqrt[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)}}\right)}^{3}} \]
    4. Applied egg-rr22.1%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right) + \left(m - n\right)}}\right)}^{3}} \]
    5. Taylor expanded in m around inf 21.6%

      \[\leadsto {\left(\sqrt[3]{\cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\right)\right)} \cdot e^{\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right) + \left(m - n\right)}}\right)}^{3} \]
    6. Step-by-step derivation
      1. *-commutative21.6%

        \[\leadsto {\left(\sqrt[3]{\cos \left(0.5 \cdot \color{blue}{\left(m \cdot K\right)}\right) \cdot e^{\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right) + \left(m - n\right)}}\right)}^{3} \]
    7. Simplified21.6%

      \[\leadsto {\left(\sqrt[3]{\cos \color{blue}{\left(0.5 \cdot \left(m \cdot K\right)\right)} \cdot e^{\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right) + \left(m - n\right)}}\right)}^{3} \]
    8. Taylor expanded in m around 0 27.9%

      \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot e^{{\left(0.5 \cdot n - M\right)}^{2} - \left(\ell + n\right)}} \]
    9. Step-by-step derivation
      1. pow-base-127.9%

        \[\leadsto \color{blue}{1} \cdot e^{{\left(0.5 \cdot n - M\right)}^{2} - \left(\ell + n\right)} \]
      2. *-lft-identity27.9%

        \[\leadsto \color{blue}{e^{{\left(0.5 \cdot n - M\right)}^{2} - \left(\ell + n\right)}} \]
      3. *-commutative27.9%

        \[\leadsto e^{{\left(\color{blue}{n \cdot 0.5} - M\right)}^{2} - \left(\ell + n\right)} \]
      4. +-commutative27.9%

        \[\leadsto e^{{\left(n \cdot 0.5 - M\right)}^{2} - \color{blue}{\left(n + \ell\right)}} \]
    10. Simplified27.9%

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

    if 14.5 < n

    1. Initial program 71.0%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. exp-diff8.7%

        \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot \color{blue}{\frac{e^{-{\left(\frac{m + n}{2} - M\right)}^{2}}}{e^{\ell - \left|m - n\right|}}} \]
      2. associate-*r/8.7%

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

      \[\leadsto \color{blue}{\frac{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}}{e^{\ell - \left(m - n\right)}}} \]
    5. Step-by-step derivation
      1. associate-/l*1.7%

        \[\leadsto \color{blue}{\frac{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right)}{\frac{e^{\ell - \left(m - n\right)}}{e^{{\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}}}} \]
      2. div-exp6.8%

        \[\leadsto \frac{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right)}{\color{blue}{e^{\left(\ell - \left(m - n\right)\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}}} \]
      3. associate--r-6.8%

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

        \[\leadsto \frac{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right)}{e^{\color{blue}{\left(n + \left(\ell - m\right)\right)} - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}} \]
    6. Simplified6.8%

      \[\leadsto \color{blue}{\frac{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right)}{e^{\left(n + \left(\ell - m\right)\right) - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}}} \]
    7. Taylor expanded in n around inf 2.5%

      \[\leadsto \frac{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right)}{e^{\color{blue}{n} - {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}}} \]
    8. Taylor expanded in m around inf 48.2%

      \[\leadsto \frac{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right)}{e^{n - \color{blue}{0.25 \cdot {m}^{2}}}} \]
    9. Taylor expanded in K around 0 68.6%

      \[\leadsto \frac{\color{blue}{\cos \left(-M\right)}}{e^{n - 0.25 \cdot {m}^{2}}} \]
    10. Step-by-step derivation
      1. cos-neg68.6%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{n - 0.25 \cdot {m}^{2}}} \]
    11. Simplified68.6%

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{n - 0.25 \cdot {m}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification38.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 14.5:\\ \;\;\;\;e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos M}{e^{n - 0.25 \cdot {m}^{2}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 86.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ e^{\left(\left|m - n\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (exp (- (- (fabs (- m n)) l) (* 0.25 (pow (+ m n) 2.0)))))
double code(double K, double m, double n, double M, double l) {
	return exp(((fabs((m - n)) - l) - (0.25 * pow((m + n), 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 = exp(((abs((m - n)) - l) - (0.25d0 * ((m + n) ** 2.0d0))))
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.exp(((Math.abs((m - n)) - l) - (0.25 * Math.pow((m + n), 2.0))));
}
def code(K, m, n, M, l):
	return math.exp(((math.fabs((m - n)) - l) - (0.25 * math.pow((m + n), 2.0))))
function code(K, m, n, M, l)
	return exp(Float64(Float64(abs(Float64(m - n)) - l) - Float64(0.25 * (Float64(m + n) ^ 2.0))))
end
function tmp = code(K, m, n, M, l)
	tmp = exp(((abs((m - n)) - l) - (0.25 * ((m + n) ^ 2.0))));
end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision] - N[(0.25 * N[Power[N[(m + n), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{\left(\left|m - n\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}}
\end{array}
Derivation
  1. Initial program 73.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. Add Preprocessing
  3. Taylor expanded in K around 0 96.1%

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

      \[\leadsto \color{blue}{\cos M} \cdot e^{\left|m - n\right| - \left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)} \]
    2. sub-neg96.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|m - n\right| + \left(-\left(\ell + {\left(0.5 \cdot \left(m + n\right) - M\right)}^{2}\right)\right)}} \]
    3. sub-neg96.1%

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

      \[\leadsto \cos M \cdot e^{\left|m - n\right| + \left(-\left(\ell + {\color{blue}{\left(\left(-M\right) + 0.5 \cdot \left(m + n\right)\right)}}^{2}\right)\right)} \]
    5. neg-mul-196.1%

      \[\leadsto \cos M \cdot e^{\left|m - n\right| + \left(-\left(\ell + {\left(\color{blue}{-1 \cdot M} + 0.5 \cdot \left(m + n\right)\right)}^{2}\right)\right)} \]
    6. sub-neg96.1%

      \[\leadsto \cos M \cdot e^{\color{blue}{\left|m - n\right| - \left(\ell + {\left(-1 \cdot M + 0.5 \cdot \left(m + n\right)\right)}^{2}\right)}} \]
  5. Simplified96.1%

    \[\leadsto \color{blue}{\cos M \cdot e^{\left|m - n\right| - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}} \]
  6. Taylor expanded in M around 0 86.2%

    \[\leadsto \color{blue}{e^{\left|m - n\right| - \left(\ell + 0.25 \cdot {\left(m + n\right)}^{2}\right)}} \]
  7. Step-by-step derivation
    1. associate--r+86.2%

      \[\leadsto e^{\color{blue}{\left(\left|m - n\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}}} \]
    2. fabs-sub86.2%

      \[\leadsto e^{\left(\color{blue}{\left|n - m\right|} - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}} \]
  8. Simplified86.2%

    \[\leadsto \color{blue}{e^{\left(\left|n - m\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}}} \]
  9. Final simplification86.2%

    \[\leadsto e^{\left(\left|m - n\right| - \ell\right) - 0.25 \cdot {\left(m + n\right)}^{2}} \]
  10. Add Preprocessing

Alternative 4: 20.8% accurate, 2.0× speedup?

\[\begin{array}{l} \\ e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (exp (- (pow (- (* n 0.5) M) 2.0) (+ n l))))
double code(double K, double m, double n, double M, double l) {
	return exp((pow(((n * 0.5) - M), 2.0) - (n + 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 = exp(((((n * 0.5d0) - m_1) ** 2.0d0) - (n + l)))
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.exp((Math.pow(((n * 0.5) - M), 2.0) - (n + l)));
}
def code(K, m, n, M, l):
	return math.exp((math.pow(((n * 0.5) - M), 2.0) - (n + l)))
function code(K, m, n, M, l)
	return exp(Float64((Float64(Float64(n * 0.5) - M) ^ 2.0) - Float64(n + l)))
end
function tmp = code(K, m, n, M, l)
	tmp = exp(((((n * 0.5) - M) ^ 2.0) - (n + l)));
end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[Power[N[(N[(n * 0.5), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision] - N[(n + l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)}
\end{array}
Derivation
  1. Initial program 73.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. Add Preprocessing
  3. Step-by-step derivation
    1. add-cube-cbrt73.4%

      \[\leadsto \color{blue}{\left(\sqrt[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)}} \cdot \sqrt[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)}}\right) \cdot \sqrt[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. pow373.4%

      \[\leadsto \color{blue}{{\left(\sqrt[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)}}\right)}^{3}} \]
  4. Applied egg-rr18.0%

    \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos \left(K \cdot \left(\left(m + n\right) \cdot 0.5\right) - M\right) \cdot e^{\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right) + \left(m - n\right)}}\right)}^{3}} \]
  5. Taylor expanded in m around inf 17.3%

    \[\leadsto {\left(\sqrt[3]{\cos \color{blue}{\left(0.5 \cdot \left(K \cdot m\right)\right)} \cdot e^{\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right) + \left(m - n\right)}}\right)}^{3} \]
  6. Step-by-step derivation
    1. *-commutative17.3%

      \[\leadsto {\left(\sqrt[3]{\cos \left(0.5 \cdot \color{blue}{\left(m \cdot K\right)}\right) \cdot e^{\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right) + \left(m - n\right)}}\right)}^{3} \]
  7. Simplified17.3%

    \[\leadsto {\left(\sqrt[3]{\cos \color{blue}{\left(0.5 \cdot \left(m \cdot K\right)\right)} \cdot e^{\left({\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2} - \ell\right) + \left(m - n\right)}}\right)}^{3} \]
  8. Taylor expanded in m around 0 22.3%

    \[\leadsto \color{blue}{{1}^{0.3333333333333333} \cdot e^{{\left(0.5 \cdot n - M\right)}^{2} - \left(\ell + n\right)}} \]
  9. Step-by-step derivation
    1. pow-base-122.3%

      \[\leadsto \color{blue}{1} \cdot e^{{\left(0.5 \cdot n - M\right)}^{2} - \left(\ell + n\right)} \]
    2. *-lft-identity22.3%

      \[\leadsto \color{blue}{e^{{\left(0.5 \cdot n - M\right)}^{2} - \left(\ell + n\right)}} \]
    3. *-commutative22.3%

      \[\leadsto e^{{\left(\color{blue}{n \cdot 0.5} - M\right)}^{2} - \left(\ell + n\right)} \]
    4. +-commutative22.3%

      \[\leadsto e^{{\left(n \cdot 0.5 - M\right)}^{2} - \color{blue}{\left(n + \ell\right)}} \]
  10. Simplified22.3%

    \[\leadsto \color{blue}{e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)}} \]
  11. Final simplification22.3%

    \[\leadsto e^{{\left(n \cdot 0.5 - M\right)}^{2} - \left(n + \ell\right)} \]
  12. Add Preprocessing

Reproduce

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