Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 76.2% → 96.8%
Time: 16.3s
Alternatives: 5
Speedup: 3.5×

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 5 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: 76.2% 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.8% accurate, 1.0× speedup?

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

\\
e^{\left|n - m\right| - \left({\left(0.5 \cdot \left(n + m\right) - M\right)}^{2} + \ell\right)} \cdot \cos M
\end{array}
Derivation
  1. Initial program 72.5%

    \[\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.0%

    \[\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. Simplified96.0%

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

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

Alternative 2: 96.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(n + m\right) - M\\ 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 (- (* 0.5 (+ n m)) 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 = (0.5 * (n + m)) - M;
	return 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 = (0.5d0 * (n + m)) - m_1
    code = 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 = (0.5 * (n + m)) - M;
	return Math.exp((Math.abs((n - m)) - ((t_0 * t_0) + l)));
}
def code(K, m, n, M, l):
	t_0 = (0.5 * (n + m)) - M
	return math.exp((math.fabs((n - m)) - ((t_0 * t_0) + l)))
function code(K, m, n, M, l)
	t_0 = Float64(Float64(0.5 * Float64(n + m)) - M)
	return exp(Float64(abs(Float64(n - m)) - Float64(Float64(t_0 * t_0) + l)))
end
function tmp = code(K, m, n, M, l)
	t_0 = (0.5 * (n + m)) - M;
	tmp = exp((abs((n - m)) - ((t_0 * t_0) + l)));
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(0.5 * N[(n + m), $MachinePrecision]), $MachinePrecision] - 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]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(n + m\right) - M\\
e^{\left|n - m\right| - \left(t\_0 \cdot t\_0 + \ell\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 72.5%

    \[\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.0%

    \[\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. Simplified96.0%

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

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

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

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

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

      \[\leadsto e^{\left|n - m\right| - \left(\ell + \color{blue}{\left(\frac{m + n}{2} - M\right) \cdot \left(\frac{m + n}{2} - M\right)}\right)} \cdot 1 \]
    5. div-inv95.3%

      \[\leadsto e^{\left|n - m\right| - \left(\ell + \left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right) \cdot \left(\frac{m + n}{2} - M\right)\right)} \cdot 1 \]
    6. metadata-eval95.3%

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

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

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

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

      \[\leadsto e^{\left|n - m\right| - \left(\ell + \left(0.5 \cdot \left(n + m\right) - M\right) \cdot \left(\left(m + n\right) \cdot \color{blue}{0.5} - M\right)\right)} \cdot 1 \]
    11. *-commutative95.3%

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

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

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

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

Alternative 3: 96.3% accurate, 3.5× speedup?

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

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(n + m\right)\\
e^{\left(m - n\right) + \left(\left(t\_0 - M\right) \cdot \left(M - t\_0\right) - \ell\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 72.5%

    \[\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.0%

    \[\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. Simplified96.0%

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

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

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

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

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

      \[\leadsto e^{\left|n - m\right| - \left(\ell + \color{blue}{\left(\frac{m + n}{2} - M\right) \cdot \left(\frac{m + n}{2} - M\right)}\right)} \cdot 1 \]
    5. div-inv95.3%

      \[\leadsto e^{\left|n - m\right| - \left(\ell + \left(\color{blue}{\left(m + n\right) \cdot \frac{1}{2}} - M\right) \cdot \left(\frac{m + n}{2} - M\right)\right)} \cdot 1 \]
    6. metadata-eval95.3%

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

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

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

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

      \[\leadsto e^{\left|n - m\right| - \left(\ell + \left(0.5 \cdot \left(n + m\right) - M\right) \cdot \left(\left(m + n\right) \cdot \color{blue}{0.5} - M\right)\right)} \cdot 1 \]
    11. *-commutative95.3%

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

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

    \[\leadsto e^{\left|n - m\right| - \left(\ell + \color{blue}{\left(0.5 \cdot \left(n + m\right) - M\right) \cdot \left(0.5 \cdot \left(n + m\right) - M\right)}\right)} \cdot 1 \]
  8. Taylor expanded in n around -inf 95.3%

    \[\leadsto e^{\color{blue}{\left|-\left(m + -1 \cdot n\right)\right|} - \left(\ell + \left(0.5 \cdot \left(n + m\right) - M\right) \cdot \left(0.5 \cdot \left(n + m\right) - M\right)\right)} \cdot 1 \]
  9. Step-by-step derivation
    1. fabs-neg95.3%

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

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

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

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

      \[\leadsto e^{\color{blue}{\sqrt{m - n} \cdot \sqrt{m - n}} - \left(\ell + \left(0.5 \cdot \left(n + m\right) - M\right) \cdot \left(0.5 \cdot \left(n + m\right) - M\right)\right)} \cdot 1 \]
    6. rem-square-sqrt95.3%

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

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

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

Alternative 4: 6.9% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \cos M \end{array} \]
(FPCore (K m n M l) :precision binary64 (cos M))
double code(double K, double m, double n, double M, double l) {
	return cos(M);
}
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)
end function
public static double code(double K, double m, double n, double M, double l) {
	return Math.cos(M);
}
def code(K, m, n, M, l):
	return math.cos(M)
function code(K, m, n, M, l)
	return cos(M)
end
function tmp = code(K, m, n, M, l)
	tmp = cos(M);
end
code[K_, m_, n_, M_, l_] := N[Cos[M], $MachinePrecision]
\begin{array}{l}

\\
\cos M
\end{array}
Derivation
  1. Initial program 72.5%

    \[\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 l around inf 30.6%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  4. Step-by-step derivation
    1. mul-1-neg30.6%

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
  7. Step-by-step derivation
    1. associate-*r*7.7%

      \[\leadsto \cos \left(\color{blue}{\left(0.5 \cdot K\right) \cdot \left(m + n\right)} - M\right) \]
  8. Simplified7.7%

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

    \[\leadsto \color{blue}{\cos \left(-M\right)} \]
  10. Step-by-step derivation
    1. cos-neg8.3%

      \[\leadsto \color{blue}{\cos M} \]
  11. Simplified8.3%

    \[\leadsto \color{blue}{\cos M} \]
  12. Add Preprocessing

Alternative 5: 6.9% accurate, 425.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (K m n M l) :precision binary64 1.0)
double code(double K, double m, double n, double M, double l) {
	return 1.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 = 1.0d0
end function
public static double code(double K, double m, double n, double M, double l) {
	return 1.0;
}
def code(K, m, n, M, l):
	return 1.0
function code(K, m, n, M, l)
	return 1.0
end
function tmp = code(K, m, n, M, l)
	tmp = 1.0;
end
code[K_, m_, n_, M_, l_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 72.5%

    \[\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 l around inf 30.6%

    \[\leadsto \cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot e^{\color{blue}{-1 \cdot \ell}} \]
  4. Step-by-step derivation
    1. mul-1-neg30.6%

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

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

    \[\leadsto \color{blue}{\cos \left(0.5 \cdot \left(K \cdot \left(m + n\right)\right) - M\right)} \]
  7. Step-by-step derivation
    1. associate-*r*7.7%

      \[\leadsto \cos \left(\color{blue}{\left(0.5 \cdot K\right) \cdot \left(m + n\right)} - M\right) \]
  8. Simplified7.7%

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

    \[\leadsto \color{blue}{\cos \left(-M\right) + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right)} \]
  10. Step-by-step derivation
    1. cos-neg7.6%

      \[\leadsto \color{blue}{\cos M} + -0.5 \cdot \left(K \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)\right) \]
    2. associate-*r*7.6%

      \[\leadsto \cos M + \color{blue}{\left(-0.5 \cdot K\right) \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right)} \]
    3. *-commutative7.6%

      \[\leadsto \cos M + \color{blue}{\left(K \cdot -0.5\right)} \cdot \left(\sin \left(-M\right) \cdot \left(m + n\right)\right) \]
    4. *-commutative7.6%

      \[\leadsto \cos M + \left(K \cdot -0.5\right) \cdot \color{blue}{\left(\left(m + n\right) \cdot \sin \left(-M\right)\right)} \]
    5. sin-neg7.6%

      \[\leadsto \cos M + \left(K \cdot -0.5\right) \cdot \left(\left(m + n\right) \cdot \color{blue}{\left(-\sin M\right)}\right) \]
  11. Simplified7.6%

    \[\leadsto \color{blue}{\cos M + \left(K \cdot -0.5\right) \cdot \left(\left(m + n\right) \cdot \left(-\sin M\right)\right)} \]
  12. Taylor expanded in M around 0 8.2%

    \[\leadsto \color{blue}{1} \]
  13. Add Preprocessing

Reproduce

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