Maksimov and Kolovsky, Equation (32)

Percentage Accurate: 75.6% → 96.5%
Time: 20.1s
Alternatives: 9
Speedup: 2.0×

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 9 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.6% 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.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}} \end{array} \]
(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(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(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(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(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(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(M) * exp(((abs((m - n)) - l) - ((((m + n) / 2.0) - M) ^ 2.0)));
end
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]
\begin{array}{l}

\\
\cos M \cdot e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 79.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 98.1%

    \[\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)} \]
  4. Step-by-step derivation
    1. cos-neg98.1%

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

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

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

Alternative 2: 87.7% accurate, 1.4× speedup?

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

\\
\cos M \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(m \cdot 0.5 - M\right)}^{2}}
\end{array}
Derivation
  1. Initial program 79.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 98.1%

    \[\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)} \]
  4. Step-by-step derivation
    1. cos-neg98.1%

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

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

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

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

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

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

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

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

      \[\leadsto \cos M \cdot e^{\left(\color{blue}{\left(m - n\right)} - \ell\right) - {\left(0.5 \cdot m - M\right)}^{2}} \]
    7. *-commutative88.5%

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

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

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

Alternative 3: 64.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-0.25 \cdot {m}^{2}}\\ \mathbf{if}\;n \leq 2.7 \cdot 10^{-198}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;n \leq 1.6 \cdot 10^{-85}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{elif}\;n \leq 720:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-n}\\ \end{array} \end{array} \]
(FPCore (K m n M l)
 :precision binary64
 (let* ((t_0 (exp (* -0.25 (pow m 2.0)))))
   (if (<= n 2.7e-198)
     t_0
     (if (<= n 1.6e-85)
       (/ (cos M) (exp l))
       (if (<= n 720.0) t_0 (* (cos M) (exp (- n))))))))
double code(double K, double m, double n, double M, double l) {
	double t_0 = exp((-0.25 * pow(m, 2.0)));
	double tmp;
	if (n <= 2.7e-198) {
		tmp = t_0;
	} else if (n <= 1.6e-85) {
		tmp = cos(M) / exp(l);
	} else if (n <= 720.0) {
		tmp = t_0;
	} else {
		tmp = cos(M) * exp(-n);
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = exp(((-0.25d0) * (m ** 2.0d0)))
    if (n <= 2.7d-198) then
        tmp = t_0
    else if (n <= 1.6d-85) then
        tmp = cos(m_1) / exp(l)
    else if (n <= 720.0d0) then
        tmp = t_0
    else
        tmp = cos(m_1) * exp(-n)
    end if
    code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
	double t_0 = Math.exp((-0.25 * Math.pow(m, 2.0)));
	double tmp;
	if (n <= 2.7e-198) {
		tmp = t_0;
	} else if (n <= 1.6e-85) {
		tmp = Math.cos(M) / Math.exp(l);
	} else if (n <= 720.0) {
		tmp = t_0;
	} else {
		tmp = Math.cos(M) * Math.exp(-n);
	}
	return tmp;
}
def code(K, m, n, M, l):
	t_0 = math.exp((-0.25 * math.pow(m, 2.0)))
	tmp = 0
	if n <= 2.7e-198:
		tmp = t_0
	elif n <= 1.6e-85:
		tmp = math.cos(M) / math.exp(l)
	elif n <= 720.0:
		tmp = t_0
	else:
		tmp = math.cos(M) * math.exp(-n)
	return tmp
function code(K, m, n, M, l)
	t_0 = exp(Float64(-0.25 * (m ^ 2.0)))
	tmp = 0.0
	if (n <= 2.7e-198)
		tmp = t_0;
	elseif (n <= 1.6e-85)
		tmp = Float64(cos(M) / exp(l));
	elseif (n <= 720.0)
		tmp = t_0;
	else
		tmp = Float64(cos(M) * exp(Float64(-n)));
	end
	return tmp
end
function tmp_2 = code(K, m, n, M, l)
	t_0 = exp((-0.25 * (m ^ 2.0)));
	tmp = 0.0;
	if (n <= 2.7e-198)
		tmp = t_0;
	elseif (n <= 1.6e-85)
		tmp = cos(M) / exp(l);
	elseif (n <= 720.0)
		tmp = t_0;
	else
		tmp = cos(M) * exp(-n);
	end
	tmp_2 = tmp;
end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[Exp[N[(-0.25 * N[Power[m, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[n, 2.7e-198], t$95$0, If[LessEqual[n, 1.6e-85], N[(N[Cos[M], $MachinePrecision] / N[Exp[l], $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 720.0], t$95$0, N[(N[Cos[M], $MachinePrecision] * N[Exp[(-n)], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-0.25 \cdot {m}^{2}}\\
\mathbf{if}\;n \leq 2.7 \cdot 10^{-198}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;n \leq 1.6 \cdot 10^{-85}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\

\mathbf{elif}\;n \leq 720:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\cos M \cdot e^{-n}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if n < 2.7000000000000002e-198 or 1.60000000000000014e-85 < n < 720

    1. Initial program 78.7%

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

      \[\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)} \]
    4. Step-by-step derivation
      1. cos-neg97.7%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative58.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    8. Simplified58.0%

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 58.0%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {m}^{2}}} \]

    if 2.7000000000000002e-198 < n < 1.60000000000000014e-85

    1. Initial program 85.8%

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

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
    7. Step-by-step derivation
      1. cos-neg59.0%

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. exp-neg59.0%

        \[\leadsto \cos M \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      3. associate-*r/59.0%

        \[\leadsto \color{blue}{\frac{\cos M \cdot 1}{e^{\ell}}} \]
      4. *-rgt-identity59.0%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    8. Simplified59.0%

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

    if 720 < n

    1. Initial program 78.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. Add Preprocessing
    3. Taylor expanded in K around 0 100.0%

      \[\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)} \]
    4. Step-by-step derivation
      1. cos-neg100.0%

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{{\left(m - n\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(m - n\right)}^{\left(\frac{1}{2}\right)}} - \ell\right) - {\left(0.5 \cdot m - M\right)}^{2}} \]
      5. sqr-pow98.3%

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

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

        \[\leadsto \cos M \cdot e^{\left(\left(m - n\right) - \ell\right) - {\left(\color{blue}{m \cdot 0.5} - M\right)}^{2}} \]
    8. Simplified98.3%

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-1 \cdot n}} \]
    10. Step-by-step derivation
      1. mul-1-neg96.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{-n}} \]
    11. Simplified96.5%

      \[\leadsto \cos M \cdot e^{\color{blue}{-n}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq 2.7 \cdot 10^{-198}:\\ \;\;\;\;e^{-0.25 \cdot {m}^{2}}\\ \mathbf{elif}\;n \leq 1.6 \cdot 10^{-85}:\\ \;\;\;\;\frac{\cos M}{e^{\ell}}\\ \mathbf{elif}\;n \leq 720:\\ \;\;\;\;e^{-0.25 \cdot {m}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos M \cdot e^{-n}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 69.0% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -0.00013 \lor \neg \left(m \leq 55\right):\\
\;\;\;\;e^{-0.25 \cdot {m}^{2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\cos M}{e^{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -1.29999999999999989e-4 or 55 < m

    1. Initial program 73.6%

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

      \[\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)} \]
    4. Step-by-step derivation
      1. cos-neg98.4%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative94.5%

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    8. Simplified94.5%

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 94.5%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {m}^{2}}} \]

    if -1.29999999999999989e-4 < m < 55

    1. Initial program 84.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. Add Preprocessing
    3. Taylor expanded in l around inf 40.3%

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

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

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

      \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
    7. Step-by-step derivation
      1. cos-neg45.8%

        \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
      2. exp-neg45.8%

        \[\leadsto \cos M \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
      3. associate-*r/45.8%

        \[\leadsto \color{blue}{\frac{\cos M \cdot 1}{e^{\ell}}} \]
      4. *-rgt-identity45.8%

        \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
    8. Simplified45.8%

      \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification69.6%

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

Alternative 5: 75.7% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;m \leq -5 \cdot 10^{+64}:\\
\;\;\;\;e^{-0.25 \cdot {m}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if m < -5e64

    1. Initial program 72.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. Taylor expanded in K around 0 100.0%

      \[\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)} \]
    4. Step-by-step derivation
      1. cos-neg100.0%

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

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

      \[\leadsto \cos M \cdot e^{\color{blue}{-0.25 \cdot {m}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative98.0%

        \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    8. Simplified98.0%

      \[\leadsto \cos M \cdot e^{\color{blue}{{m}^{2} \cdot -0.25}} \]
    9. Taylor expanded in M around 0 98.0%

      \[\leadsto \color{blue}{e^{-0.25 \cdot {m}^{2}}} \]

    if -5e64 < m

    1. Initial program 81.1%

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

      \[\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)} \]
    4. Step-by-step derivation
      1. cos-neg97.6%

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

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

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

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

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

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

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

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

        \[\leadsto \cos M \cdot e^{\left(\color{blue}{\left(m - n\right)} - \ell\right) - {\left(0.5 \cdot m - M\right)}^{2}} \]
      7. *-commutative86.1%

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

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

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

      \[\leadsto \color{blue}{1} \cdot e^{\left(\left(m - n\right) - \ell\right) - {M}^{2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.9%

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

Alternative 6: 36.0% accurate, 2.1× speedup?

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

\\
\frac{\cos M}{e^{\ell}}
\end{array}
Derivation
  1. Initial program 79.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 l around inf 31.1%

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

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

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

    \[\leadsto \color{blue}{\cos \left(-M\right) \cdot e^{-\ell}} \]
  7. Step-by-step derivation
    1. cos-neg36.9%

      \[\leadsto \color{blue}{\cos M} \cdot e^{-\ell} \]
    2. exp-neg36.9%

      \[\leadsto \cos M \cdot \color{blue}{\frac{1}{e^{\ell}}} \]
    3. associate-*r/36.9%

      \[\leadsto \color{blue}{\frac{\cos M \cdot 1}{e^{\ell}}} \]
    4. *-rgt-identity36.9%

      \[\leadsto \frac{\color{blue}{\cos M}}{e^{\ell}} \]
  8. Simplified36.9%

    \[\leadsto \color{blue}{\frac{\cos M}{e^{\ell}}} \]
  9. Final simplification36.9%

    \[\leadsto \frac{\cos M}{e^{\ell}} \]
  10. Add Preprocessing

Alternative 7: 35.4% accurate, 4.2× speedup?

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

\\
e^{-\ell}
\end{array}
Derivation
  1. Initial program 79.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 l around inf 31.1%

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

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

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

    \[\leadsto \cos \color{blue}{\left(0.5 \cdot \left(K \cdot n\right)\right)} \cdot e^{-\ell} \]
  7. Step-by-step derivation
    1. *-commutative32.8%

      \[\leadsto \cos \color{blue}{\left(\left(K \cdot n\right) \cdot 0.5\right)} \cdot e^{-\ell} \]
    2. *-commutative32.8%

      \[\leadsto \cos \left(\color{blue}{\left(n \cdot K\right)} \cdot 0.5\right) \cdot e^{-\ell} \]
    3. associate-*l*32.8%

      \[\leadsto \cos \color{blue}{\left(n \cdot \left(K \cdot 0.5\right)\right)} \cdot e^{-\ell} \]
  8. Simplified32.8%

    \[\leadsto \cos \color{blue}{\left(n \cdot \left(K \cdot 0.5\right)\right)} \cdot e^{-\ell} \]
  9. Taylor expanded in n around 0 36.9%

    \[\leadsto \color{blue}{e^{-\ell}} \]
  10. Final simplification36.9%

    \[\leadsto e^{-\ell} \]
  11. Add Preprocessing

Alternative 8: 6.8% 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 79.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 l around inf 31.1%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos M} \]
  12. Final simplification8.9%

    \[\leadsto \cos M \]
  13. Add Preprocessing

Alternative 9: 6.8% 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 79.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 l around inf 31.1%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos M} \]
  12. Taylor expanded in M around 0 8.9%

    \[\leadsto \color{blue}{1} \]
  13. Final simplification8.9%

    \[\leadsto 1 \]
  14. Add Preprocessing

Reproduce

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