
(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:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
Initial program 73.4%
Taylor expanded in K around 0 96.1%
cos-neg96.1%
sub-neg96.1%
sub-neg96.1%
+-commutative96.1%
neg-mul-196.1%
sub-neg96.1%
Simplified96.1%
unpow296.1%
Applied egg-rr96.1%
Final simplification96.1%
(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}
if n < 14.5Initial program 74.3%
add-cube-cbrt74.2%
pow374.3%
Applied egg-rr22.1%
Taylor expanded in m around inf 21.6%
*-commutative21.6%
Simplified21.6%
Taylor expanded in m around 0 27.9%
pow-base-127.9%
*-lft-identity27.9%
*-commutative27.9%
+-commutative27.9%
Simplified27.9%
if 14.5 < n Initial program 71.0%
exp-diff8.7%
associate-*r/8.7%
Applied egg-rr1.7%
associate-/l*1.7%
div-exp6.8%
associate--r-6.8%
+-commutative6.8%
Simplified6.8%
Taylor expanded in n around inf 2.5%
Taylor expanded in m around inf 48.2%
Taylor expanded in K around 0 68.6%
cos-neg68.6%
Simplified68.6%
Final simplification38.9%
(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}
Initial program 73.4%
Taylor expanded in K around 0 96.1%
cos-neg96.1%
sub-neg96.1%
sub-neg96.1%
+-commutative96.1%
neg-mul-196.1%
sub-neg96.1%
Simplified96.1%
Taylor expanded in M around 0 86.2%
associate--r+86.2%
fabs-sub86.2%
Simplified86.2%
Final simplification86.2%
(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}
Initial program 73.4%
add-cube-cbrt73.4%
pow373.4%
Applied egg-rr18.0%
Taylor expanded in m around inf 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in m around 0 22.3%
pow-base-122.3%
*-lft-identity22.3%
*-commutative22.3%
+-commutative22.3%
Simplified22.3%
Final simplification22.3%
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)))))))