
(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 6 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))) (* (cos M) (exp (+ (* (- t_0 M) (- M t_0)) (- (fabs (- m n)) l))))))
double code(double K, double m, double n, double M, double l) {
double t_0 = (m + n) * 0.5;
return cos(M) * exp((((t_0 - M) * (M - t_0)) + (fabs((m - 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
real(8) :: t_0
t_0 = (m + n) * 0.5d0
code = cos(m_1) * exp((((t_0 - m_1) * (m_1 - t_0)) + (abs((m - n)) - l)))
end function
public static double code(double K, double m, double n, double M, double l) {
double t_0 = (m + n) * 0.5;
return Math.cos(M) * Math.exp((((t_0 - M) * (M - t_0)) + (Math.abs((m - n)) - l)));
}
def code(K, m, n, M, l): t_0 = (m + n) * 0.5 return math.cos(M) * math.exp((((t_0 - M) * (M - t_0)) + (math.fabs((m - n)) - l)))
function code(K, m, n, M, l) t_0 = Float64(Float64(m + n) * 0.5) return Float64(cos(M) * exp(Float64(Float64(Float64(t_0 - M) * Float64(M - t_0)) + Float64(abs(Float64(m - n)) - l)))) end
function tmp = code(K, m, n, M, l) t_0 = (m + n) * 0.5; tmp = cos(M) * exp((((t_0 - M) * (M - t_0)) + (abs((m - n)) - l))); end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision]}, N[(N[Cos[M], $MachinePrecision] * N[Exp[N[(N[(N[(t$95$0 - M), $MachinePrecision] * N[(M - t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5\\
\cos M \cdot e^{\left(t\_0 - M\right) \cdot \left(M - t\_0\right) + \left(\left|m - n\right| - \ell\right)}
\end{array}
\end{array}
Initial program 75.5%
Taylor expanded in K around 0 98.9%
cos-neg98.9%
Simplified98.9%
div-inv98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
*-commutative98.9%
*-commutative98.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (K m n M l) :precision binary64 (let* ((t_0 (* (+ m n) 0.5))) (exp (+ (* (- t_0 M) (- M t_0)) (- (fabs (- m n)) l)))))
double code(double K, double m, double n, double M, double l) {
double t_0 = (m + n) * 0.5;
return exp((((t_0 - M) * (M - t_0)) + (fabs((m - 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
real(8) :: t_0
t_0 = (m + n) * 0.5d0
code = exp((((t_0 - m_1) * (m_1 - t_0)) + (abs((m - n)) - l)))
end function
public static double code(double K, double m, double n, double M, double l) {
double t_0 = (m + n) * 0.5;
return Math.exp((((t_0 - M) * (M - t_0)) + (Math.abs((m - n)) - l)));
}
def code(K, m, n, M, l): t_0 = (m + n) * 0.5 return math.exp((((t_0 - M) * (M - t_0)) + (math.fabs((m - n)) - l)))
function code(K, m, n, M, l) t_0 = Float64(Float64(m + n) * 0.5) return exp(Float64(Float64(Float64(t_0 - M) * Float64(M - t_0)) + Float64(abs(Float64(m - n)) - l))) end
function tmp = code(K, m, n, M, l) t_0 = (m + n) * 0.5; tmp = exp((((t_0 - M) * (M - t_0)) + (abs((m - n)) - l))); end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision]}, N[Exp[N[(N[(N[(t$95$0 - M), $MachinePrecision] * N[(M - t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[Abs[N[(m - n), $MachinePrecision]], $MachinePrecision] - l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5\\
e^{\left(t\_0 - M\right) \cdot \left(M - t\_0\right) + \left(\left|m - n\right| - \ell\right)}
\end{array}
\end{array}
Initial program 75.5%
Taylor expanded in K around 0 98.9%
cos-neg98.9%
Simplified98.9%
div-inv98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
*-commutative98.9%
*-commutative98.9%
Applied egg-rr98.9%
Taylor expanded in M around 0 97.7%
Final simplification97.7%
(FPCore (K m n M l) :precision binary64 (let* ((t_0 (* (+ m n) 0.5))) (exp (- (* (- t_0 M) (- M t_0)) l))))
double code(double K, double m, double n, double M, double l) {
double t_0 = (m + n) * 0.5;
return exp((((t_0 - M) * (M - 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
code = exp((((t_0 - m_1) * (m_1 - 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;
return Math.exp((((t_0 - M) * (M - t_0)) - l));
}
def code(K, m, n, M, l): t_0 = (m + n) * 0.5 return math.exp((((t_0 - M) * (M - t_0)) - l))
function code(K, m, n, M, l) t_0 = Float64(Float64(m + n) * 0.5) return exp(Float64(Float64(Float64(t_0 - M) * Float64(M - t_0)) - l)) end
function tmp = code(K, m, n, M, l) t_0 = (m + n) * 0.5; tmp = exp((((t_0 - M) * (M - t_0)) - l)); end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision]}, N[Exp[N[(N[(N[(t$95$0 - M), $MachinePrecision] * N[(M - t$95$0), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5\\
e^{\left(t\_0 - M\right) \cdot \left(M - t\_0\right) - \ell}
\end{array}
\end{array}
Initial program 75.5%
Taylor expanded in K around 0 98.9%
cos-neg98.9%
Simplified98.9%
div-inv98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
*-commutative98.9%
*-commutative98.9%
Applied egg-rr98.9%
Taylor expanded in M around 0 97.7%
Taylor expanded in l around inf 97.4%
Final simplification97.4%
(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 75.5%
Taylor expanded in l around inf 28.4%
mul-1-neg28.4%
Simplified28.4%
Taylor expanded in n around inf 26.3%
Taylor expanded in K around inf 26.2%
Taylor expanded in K around 0 32.7%
(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 75.5%
Taylor expanded in l around inf 28.4%
mul-1-neg28.4%
Simplified28.4%
Taylor expanded in l around 0 4.8%
associate-*r*4.8%
Simplified4.8%
Taylor expanded in K around 0 5.5%
cos-neg5.5%
Simplified5.5%
(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 75.5%
Taylor expanded in l around inf 28.4%
mul-1-neg28.4%
Simplified28.4%
Taylor expanded in l around 0 4.8%
associate-*r*4.8%
Simplified4.8%
Taylor expanded in K around 0 5.5%
cos-neg5.5%
Simplified5.5%
Taylor expanded in M around 0 5.5%
herbie shell --seed 2024182
(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)))))))