
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt(k)) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n): return (1.0 / math.sqrt(k)) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n) return Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (1.0 / sqrt(k)) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))
double code(double k, double n) {
return (1.0 / sqrt(k)) * pow(((2.0 * ((double) M_PI)) * n), ((1.0 - k) / 2.0));
}
public static double code(double k, double n) {
return (1.0 / Math.sqrt(k)) * Math.pow(((2.0 * Math.PI) * n), ((1.0 - k) / 2.0));
}
def code(k, n): return (1.0 / math.sqrt(k)) * math.pow(((2.0 * math.pi) * n), ((1.0 - k) / 2.0))
function code(k, n) return Float64(Float64(1.0 / sqrt(k)) * (Float64(Float64(2.0 * pi) * n) ^ Float64(Float64(1.0 - k) / 2.0))) end
function tmp = code(k, n) tmp = (1.0 / sqrt(k)) * (((2.0 * pi) * n) ^ ((1.0 - k) / 2.0)); end
code[k_, n_] := N[(N[(1.0 / N[Sqrt[k], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 * Pi), $MachinePrecision] * n), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \pi\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
(FPCore (k n) :precision binary64 (let* ((t_0 (* (* 2.0 n) PI))) (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = (2.0 * n) * ((double) M_PI);
return sqrt(t_0) / (sqrt(k) * pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = (2.0 * n) * Math.PI;
return Math.sqrt(t_0) / (Math.sqrt(k) * Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = (2.0 * n) * math.pi return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(Float64(2.0 * n) * pi) return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = (2.0 * n) * pi; tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[(N[Sqrt[k], $MachinePrecision] * N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot n\right) \cdot \pi\\
\frac{\sqrt{t_0}}{\sqrt{k} \cdot {t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-*r*99.4%
div-sub99.4%
metadata-eval99.4%
div-inv99.5%
pow-sub99.6%
pow1/299.6%
associate-/l/99.6%
div-inv99.6%
metadata-eval99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*r*99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (/ (pow k -0.5) (sqrt (pow (* n (* 2.0 PI)) (+ k -1.0)))))
double code(double k, double n) {
return pow(k, -0.5) / sqrt(pow((n * (2.0 * ((double) M_PI))), (k + -1.0)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) / Math.sqrt(Math.pow((n * (2.0 * Math.PI)), (k + -1.0)));
}
def code(k, n): return math.pow(k, -0.5) / math.sqrt(math.pow((n * (2.0 * math.pi)), (k + -1.0)))
function code(k, n) return Float64((k ^ -0.5) / sqrt((Float64(n * Float64(2.0 * pi)) ^ Float64(k + -1.0)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) / sqrt(((n * (2.0 * pi)) ^ (k + -1.0))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] / N[Sqrt[N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(k + -1.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{k}^{-0.5}}{\sqrt{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(k + -1\right)}}}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod88.4%
*-commutative88.4%
div-inv88.5%
*-commutative88.5%
div-inv88.5%
frac-times88.5%
Applied egg-rr88.5%
Simplified88.7%
clear-num88.7%
sqrt-div88.8%
metadata-eval88.8%
Applied egg-rr88.8%
pow1/288.8%
div-inv88.8%
unpow-prod-down99.5%
pow1/299.5%
pow-sub99.6%
pow199.6%
clear-num99.6%
pow199.6%
pow-div99.5%
*-commutative99.5%
*-commutative99.5%
associate-*l*99.5%
Applied egg-rr99.5%
unpow1/299.5%
associate-*r*99.5%
sub-neg99.5%
metadata-eval99.5%
Simplified99.5%
inv-pow99.5%
unpow-prod-down99.4%
inv-pow99.4%
pow1/299.4%
pow-flip99.5%
metadata-eval99.5%
associate-*l*99.5%
Applied egg-rr99.5%
unpow-199.5%
associate-*r/99.5%
*-rgt-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (pow (* 2.0 (* n PI)) (- 0.5 (* k 0.5)))))
double code(double k, double n) {
return pow(k, -0.5) * pow((2.0 * (n * ((double) M_PI))), (0.5 - (k * 0.5)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.pow((2.0 * (n * Math.PI)), (0.5 - (k * 0.5)));
}
def code(k, n): return math.pow(k, -0.5) * math.pow((2.0 * (n * math.pi)), (0.5 - (k * 0.5)))
function code(k, n) return Float64((k ^ -0.5) * (Float64(2.0 * Float64(n * pi)) ^ Float64(0.5 - Float64(k * 0.5)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * ((2.0 * (n * pi)) ^ (0.5 - (k * 0.5))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Power[N[(2.0 * N[(n * Pi), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot {\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(0.5 - k \cdot 0.5\right)}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.3%
pow-sqr99.5%
associate-*l*99.5%
*-commutative99.5%
associate-*l/99.5%
associate-/l*99.5%
metadata-eval99.5%
/-rgt-identity99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
div-inv99.4%
div-inv99.4%
metadata-eval99.4%
pow1/299.4%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (if (<= k 7.5e-53) (/ (sqrt (* n (* 2.0 PI))) (sqrt k)) (sqrt (/ (pow (* (* 2.0 n) PI) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 7.5e-53) {
tmp = sqrt((n * (2.0 * ((double) M_PI)))) / sqrt(k);
} else {
tmp = sqrt((pow(((2.0 * n) * ((double) M_PI)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 7.5e-53) {
tmp = Math.sqrt((n * (2.0 * Math.PI))) / Math.sqrt(k);
} else {
tmp = Math.sqrt((Math.pow(((2.0 * n) * Math.PI), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 7.5e-53: tmp = math.sqrt((n * (2.0 * math.pi))) / math.sqrt(k) else: tmp = math.sqrt((math.pow(((2.0 * n) * math.pi), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 7.5e-53) tmp = Float64(sqrt(Float64(n * Float64(2.0 * pi))) / sqrt(k)); else tmp = sqrt(Float64((Float64(Float64(2.0 * n) * pi) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 7.5e-53) tmp = sqrt((n * (2.0 * pi))) / sqrt(k); else tmp = sqrt(((((2.0 * n) * pi) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 7.5e-53], N[(N[Sqrt[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(N[(2.0 * n), $MachinePrecision] * Pi), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 7.5 \cdot 10^{-53}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(2 \cdot \pi\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\left(2 \cdot n\right) \cdot \pi\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 7.5000000000000001e-53Initial program 99.1%
add-sqr-sqrt98.7%
sqrt-unprod73.6%
*-commutative73.6%
div-inv73.7%
*-commutative73.7%
div-inv73.7%
frac-times73.7%
Applied egg-rr73.8%
Simplified74.1%
pow-sub74.1%
pow174.1%
Applied egg-rr74.1%
Taylor expanded in k around 0 74.1%
associate-*r/74.1%
*-commutative74.1%
sqrt-div99.2%
*-commutative99.2%
*-commutative99.2%
*-commutative99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*l*99.2%
Applied egg-rr99.2%
if 7.5000000000000001e-53 < k Initial program 99.6%
add-sqr-sqrt99.6%
sqrt-unprod99.6%
*-commutative99.6%
div-inv99.6%
*-commutative99.6%
div-inv99.6%
frac-times99.6%
Applied egg-rr99.6%
Simplified99.7%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (pow (* 2.0 (* n PI)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (n * ((double) M_PI))), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (n * Math.PI)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (n * math.pi)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(n * pi)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (n * pi)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(n * Pi), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.3%
pow-sqr99.5%
associate-*l*99.5%
*-commutative99.5%
associate-*l/99.5%
associate-/l*99.5%
metadata-eval99.5%
/-rgt-identity99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (sqrt (* n (* 2.0 PI))) (sqrt k)))
double code(double k, double n) {
return sqrt((n * (2.0 * ((double) M_PI)))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((n * (2.0 * Math.PI))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((n * (2.0 * math.pi))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(n * Float64(2.0 * pi))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((n * (2.0 * pi))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n \cdot \left(2 \cdot \pi\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod88.4%
*-commutative88.4%
div-inv88.5%
*-commutative88.5%
div-inv88.5%
frac-times88.5%
Applied egg-rr88.5%
Simplified88.7%
pow-sub88.8%
pow188.8%
Applied egg-rr88.8%
Taylor expanded in k around 0 40.1%
associate-*r/40.1%
*-commutative40.1%
sqrt-div50.9%
*-commutative50.9%
*-commutative50.9%
*-commutative50.9%
associate-*r*50.9%
*-commutative50.9%
associate-*l*50.9%
Applied egg-rr50.9%
Final simplification50.9%
(FPCore (k n) :precision binary64 (pow (* k (/ 0.5 (* n PI))) -0.5))
double code(double k, double n) {
return pow((k * (0.5 / (n * ((double) M_PI)))), -0.5);
}
public static double code(double k, double n) {
return Math.pow((k * (0.5 / (n * Math.PI))), -0.5);
}
def code(k, n): return math.pow((k * (0.5 / (n * math.pi))), -0.5)
function code(k, n) return Float64(k * Float64(0.5 / Float64(n * pi))) ^ -0.5 end
function tmp = code(k, n) tmp = (k * (0.5 / (n * pi))) ^ -0.5; end
code[k_, n_] := N[Power[N[(k * N[(0.5 / N[(n * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(k \cdot \frac{0.5}{n \cdot \pi}\right)}^{-0.5}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.3%
pow-sqr99.5%
associate-*l*99.5%
*-commutative99.5%
associate-*l/99.5%
associate-/l*99.5%
metadata-eval99.5%
/-rgt-identity99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
div-inv99.4%
div-inv99.4%
metadata-eval99.4%
pow1/299.4%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
add-sqr-sqrt99.3%
add-sqr-sqrt99.2%
add-sqr-sqrt99.4%
*-commutative99.4%
associate-*r*99.4%
*-commutative99.4%
metadata-eval99.4%
metadata-eval99.4%
div-inv99.4%
div-sub99.4%
sqrt-pow199.4%
sqrt-unprod99.5%
pow-prod-up99.5%
metadata-eval99.5%
inv-pow99.5%
sqrt-prod88.7%
Applied egg-rr88.9%
associate-*r*88.9%
sub-neg88.9%
metadata-eval88.9%
Simplified88.9%
Taylor expanded in k around 0 40.3%
Final simplification40.3%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (* n (/ PI k)))))
double code(double k, double n) {
return sqrt((2.0 * (n * (((double) M_PI) / k))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (n * (Math.PI / k))));
}
def code(k, n): return math.sqrt((2.0 * (n * (math.pi / k))))
function code(k, n) return sqrt(Float64(2.0 * Float64(n * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (n * (pi / k)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \left(n \cdot \frac{\pi}{k}\right)}
\end{array}
Initial program 99.4%
add-sqr-sqrt99.2%
sqrt-unprod88.4%
*-commutative88.4%
div-inv88.5%
*-commutative88.5%
div-inv88.5%
frac-times88.5%
Applied egg-rr88.5%
Simplified88.7%
pow-sub88.8%
pow188.8%
Applied egg-rr88.8%
Taylor expanded in k around 0 40.1%
expm1-log1p-u38.3%
expm1-udef36.9%
associate-/l*36.9%
Applied egg-rr36.9%
expm1-def38.2%
expm1-log1p40.1%
associate-/l*40.1%
associate-*r/40.1%
Simplified40.1%
Final simplification40.1%
herbie shell --seed 2023309
(FPCore (k n)
:name "Migdal et al, Equation (51)"
:precision binary64
(* (/ 1.0 (sqrt k)) (pow (* (* 2.0 PI) n) (/ (- 1.0 k) 2.0))))