
(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 9 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) 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}
Initial program 71.5%
Taylor expanded in K around 0 94.4%
cos-neg94.4%
Simplified94.4%
Final simplification94.4%
(FPCore (K m n M l) :precision binary64 (if (or (<= M -3.2e+17) (not (<= M 3e+16))) (* (cos M) (exp (- (pow M 2.0)))) (exp (- (fabs (- m n)) (+ l (* 0.25 (* (+ m n) (+ m n))))))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if ((M <= -3.2e+17) || !(M <= 3e+16)) {
tmp = cos(M) * exp(-pow(M, 2.0));
} else {
tmp = exp((fabs((m - n)) - (l + (0.25 * ((m + n) * (m + 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) :: tmp
if ((m_1 <= (-3.2d+17)) .or. (.not. (m_1 <= 3d+16))) then
tmp = cos(m_1) * exp(-(m_1 ** 2.0d0))
else
tmp = exp((abs((m - n)) - (l + (0.25d0 * ((m + n) * (m + n))))))
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.2e+17) || !(M <= 3e+16)) {
tmp = Math.cos(M) * Math.exp(-Math.pow(M, 2.0));
} else {
tmp = Math.exp((Math.abs((m - n)) - (l + (0.25 * ((m + n) * (m + n))))));
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if (M <= -3.2e+17) or not (M <= 3e+16): tmp = math.cos(M) * math.exp(-math.pow(M, 2.0)) else: tmp = math.exp((math.fabs((m - n)) - (l + (0.25 * ((m + n) * (m + n)))))) return tmp
function code(K, m, n, M, l) tmp = 0.0 if ((M <= -3.2e+17) || !(M <= 3e+16)) tmp = Float64(cos(M) * exp(Float64(-(M ^ 2.0)))); else tmp = exp(Float64(abs(Float64(m - n)) - Float64(l + Float64(0.25 * Float64(Float64(m + n) * Float64(m + n)))))); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if ((M <= -3.2e+17) || ~((M <= 3e+16))) tmp = cos(M) * exp(-(M ^ 2.0)); else tmp = exp((abs((m - n)) - (l + (0.25 * ((m + n) * (m + n)))))); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[M, -3.2e+17], N[Not[LessEqual[M, 3e+16]], $MachinePrecision]], N[(N[Cos[M], $MachinePrecision] * N[Exp[(-N[Power[M, 2.0], $MachinePrecision])], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(l + N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;M \leq -3.2 \cdot 10^{+17} \lor \neg \left(M \leq 3 \cdot 10^{+16}\right):\\
\;\;\;\;\cos M \cdot e^{-{M}^{2}}\\
\mathbf{else}:\\
\;\;\;\;e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}\\
\end{array}
\end{array}
if M < -3.2e17 or 3e16 < M Initial program 77.5%
Taylor expanded in K around 0 99.1%
cos-neg99.1%
Simplified99.1%
Taylor expanded in M around inf 97.3%
mul-1-neg97.3%
Simplified97.3%
if -3.2e17 < M < 3e16Initial program 66.9%
Taylor expanded in K around 0 90.7%
cos-neg90.7%
Simplified90.7%
Taylor expanded in M around 0 90.7%
unpow290.7%
+-commutative90.7%
+-commutative90.7%
Applied egg-rr90.7%
Final simplification93.6%
(FPCore (K m n M l) :precision binary64 (exp (- (fabs (- m n)) (+ l (* 0.25 (* (+ m n) (+ m n)))))))
double code(double K, double m, double n, double M, double l) {
return exp((fabs((m - n)) - (l + (0.25 * ((m + n) * (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 = exp((abs((m - n)) - (l + (0.25d0 * ((m + n) * (m + n))))))
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 * ((m + n) * (m + n))))));
}
def code(K, m, n, M, l): return math.exp((math.fabs((m - n)) - (l + (0.25 * ((m + n) * (m + n))))))
function code(K, m, n, M, l) return exp(Float64(abs(Float64(m - n)) - Float64(l + Float64(0.25 * Float64(Float64(m + n) * Float64(m + n)))))) end
function tmp = code(K, m, n, M, l) tmp = exp((abs((m - n)) - (l + (0.25 * ((m + n) * (m + n)))))); end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(l + N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left|m - n\right| - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}
\end{array}
Initial program 71.5%
Taylor expanded in K around 0 94.4%
cos-neg94.4%
Simplified94.4%
Taylor expanded in M around 0 82.9%
unpow282.9%
+-commutative82.9%
+-commutative82.9%
Applied egg-rr82.9%
Final simplification82.9%
(FPCore (K m n M l) :precision binary64 (exp (- (fabs n) (+ l (* 0.25 (* (+ m n) (+ m n)))))))
double code(double K, double m, double n, double M, double l) {
return exp((fabs(n) - (l + (0.25 * ((m + n) * (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 = exp((abs(n) - (l + (0.25d0 * ((m + n) * (m + n))))))
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.exp((Math.abs(n) - (l + (0.25 * ((m + n) * (m + n))))));
}
def code(K, m, n, M, l): return math.exp((math.fabs(n) - (l + (0.25 * ((m + n) * (m + n))))))
function code(K, m, n, M, l) return exp(Float64(abs(n) - Float64(l + Float64(0.25 * Float64(Float64(m + n) * Float64(m + n)))))) end
function tmp = code(K, m, n, M, l) tmp = exp((abs(n) - (l + (0.25 * ((m + n) * (m + n)))))); end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[Abs[n], $MachinePrecision] - N[(l + N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left|n\right| - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}
\end{array}
Initial program 71.5%
Taylor expanded in K around 0 94.4%
cos-neg94.4%
Simplified94.4%
Taylor expanded in M around 0 82.9%
unpow282.9%
+-commutative82.9%
+-commutative82.9%
Applied egg-rr82.9%
Taylor expanded in m around 0 82.7%
neg-mul-182.7%
Simplified82.7%
Final simplification82.7%
(FPCore (K m n M l) :precision binary64 (exp (- (fabs m) (+ l (* 0.25 (* (+ m n) (+ m n)))))))
double code(double K, double m, double n, double M, double l) {
return exp((fabs(m) - (l + (0.25 * ((m + n) * (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 = exp((abs(m) - (l + (0.25d0 * ((m + n) * (m + n))))))
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.exp((Math.abs(m) - (l + (0.25 * ((m + n) * (m + n))))));
}
def code(K, m, n, M, l): return math.exp((math.fabs(m) - (l + (0.25 * ((m + n) * (m + n))))))
function code(K, m, n, M, l) return exp(Float64(abs(m) - Float64(l + Float64(0.25 * Float64(Float64(m + n) * Float64(m + n)))))) end
function tmp = code(K, m, n, M, l) tmp = exp((abs(m) - (l + (0.25 * ((m + n) * (m + n)))))); end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[Abs[m], $MachinePrecision] - N[(l + N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left|m\right| - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}
\end{array}
Initial program 71.5%
Taylor expanded in K around 0 94.4%
cos-neg94.4%
Simplified94.4%
Taylor expanded in M around 0 82.9%
unpow282.9%
+-commutative82.9%
+-commutative82.9%
Applied egg-rr82.9%
Taylor expanded in m around inf 82.7%
Final simplification82.7%
(FPCore (K m n M l) :precision binary64 (exp (- (- m n) (+ l (* 0.25 (* (+ m n) (+ m n)))))))
double code(double K, double m, double n, double M, double l) {
return exp(((m - n) - (l + (0.25 * ((m + n) * (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 = exp(((m - n) - (l + (0.25d0 * ((m + n) * (m + n))))))
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.exp(((m - n) - (l + (0.25 * ((m + n) * (m + n))))));
}
def code(K, m, n, M, l): return math.exp(((m - n) - (l + (0.25 * ((m + n) * (m + n))))))
function code(K, m, n, M, l) return exp(Float64(Float64(m - n) - Float64(l + Float64(0.25 * Float64(Float64(m + n) * Float64(m + n)))))) end
function tmp = code(K, m, n, M, l) tmp = exp(((m - n) - (l + (0.25 * ((m + n) * (m + n)))))); end
code[K_, m_, n_, M_, l_] := N[Exp[N[(N[(m - n), $MachinePrecision] - N[(l + N[(0.25 * N[(N[(m + n), $MachinePrecision] * N[(m + n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(m - n\right) - \left(\ell + 0.25 \cdot \left(\left(m + n\right) \cdot \left(m + n\right)\right)\right)}
\end{array}
Initial program 71.5%
Taylor expanded in K around 0 94.4%
cos-neg94.4%
Simplified94.4%
Taylor expanded in M around 0 82.9%
unpow282.9%
+-commutative82.9%
+-commutative82.9%
Applied egg-rr82.9%
Taylor expanded in m around -inf 82.9%
fabs-neg82.9%
mul-1-neg82.9%
sub-neg82.9%
fabs-sub82.9%
rem-square-sqrt46.0%
fabs-sqr46.0%
rem-square-sqrt82.5%
Simplified82.5%
Final simplification82.5%
(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}
Initial program 71.5%
Taylor expanded in l around inf 28.8%
mul-1-neg28.8%
Simplified28.8%
Taylor expanded in n around inf 27.1%
associate-/l*25.4%
Simplified25.4%
Taylor expanded in K around inf 25.6%
associate-*r*25.9%
*-commutative25.9%
Simplified25.9%
Taylor expanded in K around 0 35.4%
(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}
Initial program 71.5%
Taylor expanded in l around inf 28.8%
mul-1-neg28.8%
Simplified28.8%
Taylor expanded in l around 0 6.7%
Taylor expanded in K around 0 7.3%
neg-mul-17.3%
Simplified7.3%
Taylor expanded in M around -inf 7.3%
neg-mul-17.3%
cos-neg7.3%
Simplified7.3%
(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}
Initial program 71.5%
Taylor expanded in l around inf 28.8%
mul-1-neg28.8%
Simplified28.8%
Taylor expanded in l around 0 6.7%
Taylor expanded in K around 0 7.3%
neg-mul-17.3%
Simplified7.3%
Taylor expanded in M around 0 7.3%
herbie shell --seed 2024145
(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)))))))