
(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 7 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))
(t_1 (cbrt t_0))
(t_2 (exp (- (- (fabs (- m n)) l) (pow (- (/ (+ m n) 2.0) M) 2.0))))
(t_3 (- t_0 M)))
(if (<= (* (cos (- (/ (* K (+ m n)) 2.0) M)) t_2) INFINITY)
(* t_2 (cos (- (* t_1 (* K (pow t_1 2.0))) M)))
(exp (- (- m n) (+ l (* t_3 t_3)))))))
double code(double K, double m, double n, double M, double l) {
double t_0 = (m + n) * 0.5;
double t_1 = cbrt(t_0);
double t_2 = exp(((fabs((m - n)) - l) - pow((((m + n) / 2.0) - M), 2.0)));
double t_3 = t_0 - M;
double tmp;
if ((cos((((K * (m + n)) / 2.0) - M)) * t_2) <= ((double) INFINITY)) {
tmp = t_2 * cos(((t_1 * (K * pow(t_1, 2.0))) - M));
} else {
tmp = exp(((m - n) - (l + (t_3 * t_3))));
}
return tmp;
}
public static double code(double K, double m, double n, double M, double l) {
double t_0 = (m + n) * 0.5;
double t_1 = Math.cbrt(t_0);
double t_2 = Math.exp(((Math.abs((m - n)) - l) - Math.pow((((m + n) / 2.0) - M), 2.0)));
double t_3 = t_0 - M;
double tmp;
if ((Math.cos((((K * (m + n)) / 2.0) - M)) * t_2) <= Double.POSITIVE_INFINITY) {
tmp = t_2 * Math.cos(((t_1 * (K * Math.pow(t_1, 2.0))) - M));
} else {
tmp = Math.exp(((m - n) - (l + (t_3 * t_3))));
}
return tmp;
}
function code(K, m, n, M, l) t_0 = Float64(Float64(m + n) * 0.5) t_1 = cbrt(t_0) t_2 = exp(Float64(Float64(abs(Float64(m - n)) - l) - (Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0))) t_3 = Float64(t_0 - M) tmp = 0.0 if (Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * t_2) <= Inf) tmp = Float64(t_2 * cos(Float64(Float64(t_1 * Float64(K * (t_1 ^ 2.0))) - M))); else tmp = exp(Float64(Float64(m - n) - Float64(l + Float64(t_3 * t_3)))); end return tmp end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 1/3], $MachinePrecision]}, Block[{t$95$2 = 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]}, Block[{t$95$3 = N[(t$95$0 - M), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(N[(N[(K * N[(m + n), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision] * t$95$2), $MachinePrecision], Infinity], N[(t$95$2 * N[Cos[N[(N[(t$95$1 * N[(K * N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - M), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Exp[N[(N[(m - n), $MachinePrecision] - N[(l + N[(t$95$3 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5\\
t_1 := \sqrt[3]{t\_0}\\
t_2 := e^{\left(\left|m - n\right| - \ell\right) - {\left(\frac{m + n}{2} - M\right)}^{2}}\\
t_3 := t\_0 - M\\
\mathbf{if}\;\cos \left(\frac{K \cdot \left(m + n\right)}{2} - M\right) \cdot t\_2 \leq \infty:\\
\;\;\;\;t\_2 \cdot \cos \left(t\_1 \cdot \left(K \cdot {t\_1}^{2}\right) - M\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\left(m - n\right) - \left(\ell + t\_3 \cdot t\_3\right)}\\
\end{array}
\end{array}
if (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) < +inf.0Initial program 94.0%
associate-/l*94.0%
add-cube-cbrt96.5%
associate-*r*96.5%
pow296.5%
div-inv96.5%
metadata-eval96.5%
div-inv96.5%
metadata-eval96.5%
Applied egg-rr96.5%
if +inf.0 < (*.f64 (cos.f64 (-.f64 (/.f64 (*.f64 K (+.f64 m n)) #s(literal 2 binary64)) M)) (exp.f64 (-.f64 (neg.f64 (pow.f64 (-.f64 (/.f64 (+.f64 m n) #s(literal 2 binary64)) M) #s(literal 2 binary64))) (-.f64 l (fabs.f64 (-.f64 m n)))))) Initial program 0.0%
Taylor expanded in K around 0 100.0%
Simplified100.0%
Taylor expanded in M around 0 100.0%
unpow2100.0%
Applied egg-rr100.0%
Taylor expanded in m around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt50.0%
fabs-sqr50.0%
rem-square-sqrt100.0%
Simplified100.0%
Final simplification97.1%
(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 77.9%
Taylor expanded in K around 0 95.3%
Simplified95.3%
(FPCore (K m n M l) :precision binary64 (let* ((t_0 (- (* (+ m n) 0.5) M))) (exp (- (fabs (- m n)) (+ l (* t_0 t_0))))))
double code(double K, double m, double n, double M, double l) {
double t_0 = ((m + n) * 0.5) - M;
return exp((fabs((m - n)) - (l + (t_0 * t_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
real(8) :: t_0
t_0 = ((m + n) * 0.5d0) - m_1
code = exp((abs((m - n)) - (l + (t_0 * t_0))))
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.exp((Math.abs((m - n)) - (l + (t_0 * t_0))));
}
def code(K, m, n, M, l): t_0 = ((m + n) * 0.5) - M return math.exp((math.fabs((m - n)) - (l + (t_0 * t_0))))
function code(K, m, n, M, l) t_0 = Float64(Float64(Float64(m + n) * 0.5) - M) return exp(Float64(abs(Float64(m - n)) - Float64(l + Float64(t_0 * t_0)))) end
function tmp = code(K, m, n, M, l) t_0 = ((m + n) * 0.5) - M; tmp = exp((abs((m - n)) - (l + (t_0 * t_0)))); end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision] - M), $MachinePrecision]}, N[Exp[N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - N[(l + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5 - M\\
e^{\left|m - n\right| - \left(\ell + t\_0 \cdot t\_0\right)}
\end{array}
\end{array}
Initial program 77.9%
Taylor expanded in K around 0 95.3%
Simplified95.3%
Taylor expanded in M around 0 95.1%
unpow295.1%
Applied egg-rr95.1%
Final simplification95.1%
(FPCore (K m n M l) :precision binary64 (let* ((t_0 (- (* (+ m n) 0.5) M))) (exp (- (- m n) (+ l (* t_0 t_0))))))
double code(double K, double m, double n, double M, double l) {
double t_0 = ((m + n) * 0.5) - M;
return exp(((m - n) - (l + (t_0 * t_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
real(8) :: t_0
t_0 = ((m + n) * 0.5d0) - m_1
code = exp(((m - n) - (l + (t_0 * t_0))))
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.exp(((m - n) - (l + (t_0 * t_0))));
}
def code(K, m, n, M, l): t_0 = ((m + n) * 0.5) - M return math.exp(((m - n) - (l + (t_0 * t_0))))
function code(K, m, n, M, l) t_0 = Float64(Float64(Float64(m + n) * 0.5) - M) return exp(Float64(Float64(m - n) - Float64(l + Float64(t_0 * t_0)))) end
function tmp = code(K, m, n, M, l) t_0 = ((m + n) * 0.5) - M; tmp = exp(((m - n) - (l + (t_0 * t_0)))); end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision] - M), $MachinePrecision]}, N[Exp[N[(N[(m - n), $MachinePrecision] - N[(l + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5 - M\\
e^{\left(m - n\right) - \left(\ell + t\_0 \cdot t\_0\right)}
\end{array}
\end{array}
Initial program 77.9%
Taylor expanded in K around 0 95.3%
Simplified95.3%
Taylor expanded in M around 0 95.1%
unpow295.1%
Applied egg-rr95.1%
Taylor expanded in m around -inf 95.1%
fabs-neg95.1%
mul-1-neg95.1%
sub-neg95.1%
fabs-sub95.1%
rem-square-sqrt45.8%
fabs-sqr45.8%
rem-square-sqrt94.5%
Simplified94.5%
Final simplification94.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 77.9%
Taylor expanded in l around inf 33.0%
mul-1-neg33.0%
Simplified33.0%
Taylor expanded in K around 0 35.4%
cos-neg35.4%
associate-*r*35.4%
sin-neg35.4%
Simplified35.4%
Taylor expanded in M around 0 37.2%
(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 77.9%
Taylor expanded in l around inf 33.0%
mul-1-neg33.0%
Simplified33.0%
Taylor expanded in l around 0 7.1%
Taylor expanded in K around 0 7.6%
cos-neg7.6%
Simplified7.6%
(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 77.9%
Taylor expanded in l around inf 33.0%
mul-1-neg33.0%
Simplified33.0%
Taylor expanded in l around 0 7.1%
Taylor expanded in K around 0 7.6%
cos-neg7.6%
Simplified7.6%
Taylor expanded in M around 0 7.6%
herbie shell --seed 2024132
(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)))))))