
(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 (let* ((t_0 (* (+ m n) 0.5))) (* (cos M) (exp (+ (- (* (- t_0 M) (- M t_0)) l) (fabs (- n m)))))))
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)) - l) + fabs((n - 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
real(8) :: t_0
t_0 = (m + n) * 0.5d0
code = cos(m_1) * exp(((((t_0 - m_1) * (m_1 - t_0)) - l) + abs((n - m))))
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)) - l) + Math.abs((n - m))));
}
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)) - l) + math.fabs((n - m))))
function code(K, m, n, M, l) t_0 = Float64(Float64(m + n) * 0.5) return Float64(cos(M) * exp(Float64(Float64(Float64(Float64(t_0 - M) * Float64(M - t_0)) - l) + abs(Float64(n - m))))) 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)) - l) + abs((n - m)))); 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[(N[(t$95$0 - M), $MachinePrecision] * N[(M - t$95$0), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision] + N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5\\
\cos M \cdot e^{\left(\left(t_0 - M\right) \cdot \left(M - t_0\right) - \ell\right) + \left|n - m\right|}
\end{array}
\end{array}
(FPCore (K m n M l) :precision binary64 (let* ((t_0 (* (+ m n) 0.5))) (exp (+ (- (* (- t_0 M) (- M t_0)) l) (fabs (- n m))))))
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) + fabs((n - 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
real(8) :: t_0
t_0 = (m + n) * 0.5d0
code = exp(((((t_0 - m_1) * (m_1 - t_0)) - l) + abs((n - m))))
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) + Math.abs((n - m))));
}
def code(K, m, n, M, l): t_0 = (m + n) * 0.5 return math.exp(((((t_0 - M) * (M - t_0)) - l) + math.fabs((n - m))))
function code(K, m, n, M, l) t_0 = Float64(Float64(m + n) * 0.5) return exp(Float64(Float64(Float64(Float64(t_0 - M) * Float64(M - t_0)) - l) + abs(Float64(n - m)))) end
function tmp = code(K, m, n, M, l) t_0 = (m + n) * 0.5; tmp = exp(((((t_0 - M) * (M - t_0)) - l) + abs((n - m)))); end
code[K_, m_, n_, M_, l_] := Block[{t$95$0 = N[(N[(m + n), $MachinePrecision] * 0.5), $MachinePrecision]}, N[Exp[N[(N[(N[(N[(t$95$0 - M), $MachinePrecision] * N[(M - t$95$0), $MachinePrecision]), $MachinePrecision] - l), $MachinePrecision] + N[Abs[N[(n - m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(m + n\right) \cdot 0.5\\
e^{\left(\left(t_0 - M\right) \cdot \left(M - t_0\right) - \ell\right) + \left|n - m\right|}
\end{array}
\end{array}
(FPCore (K m n M l) :precision binary64 (if (or (<= m -800000.0) (not (<= m 4e-9))) (exp (* (pow m 2.0) -0.25)) (exp (- l))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if ((m <= -800000.0) || !(m <= 4e-9)) {
tmp = exp((pow(m, 2.0) * -0.25));
} else {
tmp = exp(-l);
}
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 <= (-800000.0d0)) .or. (.not. (m <= 4d-9))) then
tmp = exp(((m ** 2.0d0) * (-0.25d0)))
else
tmp = exp(-l)
end if
code = tmp
end function
public static double code(double K, double m, double n, double M, double l) {
double tmp;
if ((m <= -800000.0) || !(m <= 4e-9)) {
tmp = Math.exp((Math.pow(m, 2.0) * -0.25));
} else {
tmp = Math.exp(-l);
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if (m <= -800000.0) or not (m <= 4e-9): tmp = math.exp((math.pow(m, 2.0) * -0.25)) else: tmp = math.exp(-l) return tmp
function code(K, m, n, M, l) tmp = 0.0 if ((m <= -800000.0) || !(m <= 4e-9)) tmp = exp(Float64((m ^ 2.0) * -0.25)); else tmp = exp(Float64(-l)); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if ((m <= -800000.0) || ~((m <= 4e-9))) tmp = exp(((m ^ 2.0) * -0.25)); else tmp = exp(-l); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[Or[LessEqual[m, -800000.0], N[Not[LessEqual[m, 4e-9]], $MachinePrecision]], N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision], N[Exp[(-l)], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -800000 \lor \neg \left(m \leq 4 \cdot 10^{-9}\right):\\
\;\;\;\;e^{{m}^{2} \cdot -0.25}\\
\mathbf{else}:\\
\;\;\;\;e^{-\ell}\\
\end{array}
\end{array}
(FPCore (K m n M l) :precision binary64 (if (<= m -800000.0) (exp (* (pow m 2.0) -0.25)) (if (<= m -9.8e-129) (exp (- l)) (exp (* -0.25 (pow n 2.0))))))
double code(double K, double m, double n, double M, double l) {
double tmp;
if (m <= -800000.0) {
tmp = exp((pow(m, 2.0) * -0.25));
} else if (m <= -9.8e-129) {
tmp = exp(-l);
} else {
tmp = exp((-0.25 * pow(n, 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 <= (-800000.0d0)) then
tmp = exp(((m ** 2.0d0) * (-0.25d0)))
else if (m <= (-9.8d-129)) then
tmp = exp(-l)
else
tmp = exp(((-0.25d0) * (n ** 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 <= -800000.0) {
tmp = Math.exp((Math.pow(m, 2.0) * -0.25));
} else if (m <= -9.8e-129) {
tmp = Math.exp(-l);
} else {
tmp = Math.exp((-0.25 * Math.pow(n, 2.0)));
}
return tmp;
}
def code(K, m, n, M, l): tmp = 0 if m <= -800000.0: tmp = math.exp((math.pow(m, 2.0) * -0.25)) elif m <= -9.8e-129: tmp = math.exp(-l) else: tmp = math.exp((-0.25 * math.pow(n, 2.0))) return tmp
function code(K, m, n, M, l) tmp = 0.0 if (m <= -800000.0) tmp = exp(Float64((m ^ 2.0) * -0.25)); elseif (m <= -9.8e-129) tmp = exp(Float64(-l)); else tmp = exp(Float64(-0.25 * (n ^ 2.0))); end return tmp end
function tmp_2 = code(K, m, n, M, l) tmp = 0.0; if (m <= -800000.0) tmp = exp(((m ^ 2.0) * -0.25)); elseif (m <= -9.8e-129) tmp = exp(-l); else tmp = exp((-0.25 * (n ^ 2.0))); end tmp_2 = tmp; end
code[K_, m_, n_, M_, l_] := If[LessEqual[m, -800000.0], N[Exp[N[(N[Power[m, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision], If[LessEqual[m, -9.8e-129], N[Exp[(-l)], $MachinePrecision], N[Exp[N[(-0.25 * N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;m \leq -800000:\\
\;\;\;\;e^{{m}^{2} \cdot -0.25}\\
\mathbf{elif}\;m \leq -9.8 \cdot 10^{-129}:\\
\;\;\;\;e^{-\ell}\\
\mathbf{else}:\\
\;\;\;\;e^{-0.25 \cdot {n}^{2}}\\
\end{array}
\end{array}
(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}
herbie shell --seed 2024010
(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)))))))