
(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 5 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 (* (cos M) (exp (- (fabs (- m n)) (+ l (pow (- (* (+ m n) 0.5) 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) * 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((abs((m - n)) - (l + ((((m + n) * 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((Math.abs((m - n)) - (l + Math.pow((((m + n) * 0.5) - 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) * 0.5) - M), 2.0))))
function code(K, m, n, M, l) return Float64(cos(M) * exp(Float64(abs(Float64(m - n)) - Float64(l + (Float64(Float64(Float64(m + n) * 0.5) - M) ^ 2.0))))) end
function tmp = code(K, m, n, M, l) tmp = cos(M) * exp((abs((m - n)) - (l + ((((m + n) * 0.5) - M) ^ 2.0)))); end
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(l + N[Power[N[(N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision] - M), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos M \cdot e^{\left|m - n\right| - \left(\ell + {\left(\left(m + n\right) \cdot 0.5 - M\right)}^{2}\right)}
\end{array}
Initial program 72.7%
Taylor expanded in K around 0 97.6%
cos-neg97.6%
sub-neg97.6%
sub-neg97.6%
+-commutative97.6%
neg-mul-197.6%
sub-neg97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (K m n M l) :precision binary64 (if (or (<= M -3.1e+75) (not (<= M 6.6e+72))) (* (cos M) (exp (- (pow M 2.0)))) (/ (cos M) (exp (- (+ n (- l m)) (pow M 2.0))))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if ((M <= -3.1e+75) || !(M <= 6.6e+72)) {
tmp = cos(M) * exp(-pow(M, 2.0));
} else {
tmp = cos(M) / exp(((n + (l - m)) - 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_1 <= (-3.1d+75)) .or. (.not. (m_1 <= 6.6d+72))) then
tmp = cos(m_1) * exp(-(m_1 ** 2.0d0))
else
tmp = cos(m_1) / exp(((n + (l - m)) - (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 <= -3.1e+75) || !(M <= 6.6e+72)) {
tmp = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
} else {
tmp = Math.cos(M) / Math.exp(((n + (l - m)) - Math.pow(M, 2.0)));
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if (M <= -3.1e+75) or not (M <= 6.6e+72): tmp = math.cos(M) * math.exp(-math.pow(M, 2.0)) else: tmp = math.cos(M) / math.exp(((n + (l - m)) - math.pow(M, 2.0))) return tmp
function code(K, m, n, M, l) tmp = 0.0 if ((M <= -3.1e+75) || !(M <= 6.6e+72)) tmp = Float64(cos(M) * exp(Float64(-(M ^ 2.0)))); else tmp = Float64(cos(M) / exp(Float64(Float64(n + Float64(l - m)) - (M ^ 2.0)))); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if ((M <= -3.1e+75) || ~((M <= 6.6e+72))) tmp = cos(M) * exp(-(M ^ 2.0)); else tmp = cos(M) / exp(((n + (l - m)) - (M ^ 2.0))); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[M, -3.1e+75], N[Not[LessEqual[M, 6.6e+72]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(N[(n + N[(l - m), $MachinePrecision]), $MachinePrecision] - N[Power[M, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;M \leq -3.1 \cdot 10^{+75} \lor \neg \left(M \leq 6.6 \cdot 10^{+72}\right):\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos M}{e^{\left(n + \left(\ell - m\right)\right) - {M}^{2}}}\\
\end{array}
\end{array}
if M < -3.1000000000000001e75 or 6.6e72 < M Initial program 79.8%
Taylor expanded in K around 0 100.0%
cos-neg100.0%
sub-neg100.0%
sub-neg100.0%
+-commutative100.0%
neg-mul-1100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in M around inf 95.5%
Taylor expanded in M around inf 100.0%
mul-1-neg100.0%
Simplified100.0%
if -3.1000000000000001e75 < M < 6.6e72Initial program 67.4%
exp-diff23.8%
associate-*r/23.8%
Applied egg-rr23.4%
associate-/l*23.4%
div-exp27.2%
associate--r-27.2%
+-commutative27.2%
Simplified27.2%
Taylor expanded in K around 0 30.8%
cos-neg30.8%
Simplified30.8%
Taylor expanded in M around inf 68.3%
Final simplification81.8%
(FPCore (K m n M l) :precision binary64 (if (or (<= M -1.1e+67) (not (<= M 820.0))) (* (cos M) (exp (- (pow M 2.0)))) (/ (cos M) (exp (- l m)))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if ((M <= -1.1e+67) || !(M <= 820.0)) {
tmp = cos(M) * exp(-pow(M, 2.0));
} else {
tmp = cos(M) / exp((l - m));
}
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_1 <= (-1.1d+67)) .or. (.not. (m_1 <= 820.0d0))) then
tmp = cos(m_1) * exp(-(m_1 ** 2.0d0))
else
tmp = cos(m_1) / exp((l - m))
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double tmp;
if ((M <= -1.1e+67) || !(M <= 820.0)) {
tmp = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
} else {
tmp = Math.cos(M) / Math.exp((l - m));
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if (M <= -1.1e+67) or not (M <= 820.0): tmp = math.cos(M) * math.exp(-math.pow(M, 2.0)) else: tmp = math.cos(M) / math.exp((l - m)) return tmp
function code(K, m, n, M, l) tmp = 0.0 if ((M <= -1.1e+67) || !(M <= 820.0)) tmp = Float64(cos(M) * exp(Float64(-(M ^ 2.0)))); else tmp = Float64(cos(M) / exp(Float64(l - m))); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if ((M <= -1.1e+67) || ~((M <= 820.0))) tmp = cos(M) * exp(-(M ^ 2.0)); else tmp = cos(M) / exp((l - m)); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[M, -1.1e+67], N[Not[LessEqual[M, 820.0]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision], N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(l - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;M \leq -1.1 \cdot 10^{+67} \lor \neg \left(M \leq 820\right):\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos M}{e^{\ell - m}}\\
\end{array}
\end{array}
if M < -1.1e67 or 820 < M Initial program 78.8%
Taylor expanded in K around 0 100.0%
cos-neg100.0%
sub-neg100.0%
sub-neg100.0%
+-commutative100.0%
neg-mul-1100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in M around inf 90.8%
Taylor expanded in M around inf 98.3%
mul-1-neg98.3%
Simplified98.3%
if -1.1e67 < M < 820Initial program 67.4%
exp-diff24.7%
associate-*r/24.7%
Applied egg-rr24.2%
associate-/l*24.2%
div-exp28.2%
associate--r-28.2%
+-commutative28.2%
Simplified28.2%
Taylor expanded in n around inf 38.2%
Taylor expanded in n around 0 52.8%
Taylor expanded in K around 0 62.8%
cos-neg62.8%
Simplified62.8%
Final simplification79.2%
(FPCore (K m n M l) :precision binary64 (/ (cos M) (exp (- l m))))
double code(double K, double m, double n, double M, double l) {
return cos(M) / exp((l - 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) / exp((l - m))
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.cos(M) / Math.exp((l - m));
}
def code(K, m, n, M, l): return math.cos(M) / math.exp((l - m))
function code(K, m, n, M, l) return Float64(cos(M) / exp(Float64(l - m))) end
function tmp = code(K, m, n, M, l) tmp = cos(M) / exp((l - m)); end
code[K_, m_, n_, M_, l_] := N[(N[Cos[M], $MachinePrecision] / N[Exp[N[(l - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos M}{e^{\ell - m}}
\end{array}
Initial program 72.7%
exp-diff24.2%
associate-*r/24.2%
Applied egg-rr13.8%
associate-/l*13.8%
div-exp16.5%
associate--r-16.5%
+-commutative16.5%
Simplified16.5%
Taylor expanded in n around inf 30.9%
Taylor expanded in n around 0 42.0%
Taylor expanded in K around 0 51.0%
cos-neg51.0%
Simplified51.0%
Final simplification51.0%
(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}
Initial program 72.7%
exp-diff24.2%
associate-*r/24.2%
Applied egg-rr13.8%
associate-/l*13.8%
div-exp16.5%
associate--r-16.5%
+-commutative16.5%
Simplified16.5%
Taylor expanded in n around inf 30.9%
Taylor expanded in n around 0 42.0%
Taylor expanded in m around 0 33.3%
cos-neg33.3%
Simplified33.3%
Final simplification33.3%
herbie shell --seed 2024035
(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)))))))