
(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 5 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 (* (* n 2.0) PI))) (* (pow k -0.5) (/ (sqrt t_0) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = (n * 2.0) * ((double) M_PI);
return pow(k, -0.5) * (sqrt(t_0) / pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = (n * 2.0) * Math.PI;
return Math.pow(k, -0.5) * (Math.sqrt(t_0) / Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = (n * 2.0) * math.pi return math.pow(k, -0.5) * (math.sqrt(t_0) / math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(Float64(n * 2.0) * pi) return Float64((k ^ -0.5) * Float64(sqrt(t_0) / (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = (n * 2.0) * pi; tmp = (k ^ -0.5) * (sqrt(t_0) / (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[k, -0.5], $MachinePrecision] * N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Power[t$95$0, N[(k * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(n \cdot 2\right) \cdot \pi\\
{k}^{-0.5} \cdot \frac{\sqrt{t_0}}{{t_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.4%
div-sub99.4%
metadata-eval99.4%
pow-sub99.7%
pow1/299.7%
associate-*l*99.7%
associate-*l*99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
*-commutative99.7%
associate-*r*99.7%
*-commutative99.7%
*-commutative99.7%
Simplified99.7%
expm1-log1p-u96.8%
expm1-udef68.3%
inv-pow68.3%
sqrt-pow268.3%
metadata-eval68.3%
Applied egg-rr68.3%
expm1-def96.8%
expm1-log1p99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (k n) :precision binary64 (/ (pow (* (* n 2.0) PI) (/ (- 1.0 k) 2.0)) (sqrt k)))
double code(double k, double n) {
return pow(((n * 2.0) * ((double) M_PI)), ((1.0 - k) / 2.0)) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow(((n * 2.0) * Math.PI), ((1.0 - k) / 2.0)) / Math.sqrt(k);
}
def code(k, n): return math.pow(((n * 2.0) * math.pi), ((1.0 - k) / 2.0)) / math.sqrt(k)
function code(k, n) return Float64((Float64(Float64(n * 2.0) * pi) ^ Float64(Float64(1.0 - k) / 2.0)) / sqrt(k)) end
function tmp = code(k, n) tmp = (((n * 2.0) * pi) ^ ((1.0 - k) / 2.0)) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision], N[(N[(1.0 - k), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\left(n \cdot 2\right) \cdot \pi\right)}^{\left(\frac{1 - k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
associate-*l/99.5%
*-lft-identity99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (sqrt (/ (pow (* (* n 2.0) PI) (- 1.0 k)) k)))
double code(double k, double n) {
return sqrt((pow(((n * 2.0) * ((double) M_PI)), (1.0 - k)) / k));
}
public static double code(double k, double n) {
return Math.sqrt((Math.pow(((n * 2.0) * Math.PI), (1.0 - k)) / k));
}
def code(k, n): return math.sqrt((math.pow(((n * 2.0) * math.pi), (1.0 - k)) / k))
function code(k, n) return sqrt(Float64((Float64(Float64(n * 2.0) * pi) ^ Float64(1.0 - k)) / k)) end
function tmp = code(k, n) tmp = sqrt(((((n * 2.0) * pi) ^ (1.0 - k)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[Power[N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{{\left(\left(n \cdot 2\right) \cdot \pi\right)}^{\left(1 - k\right)}}{k}}
\end{array}
Initial program 99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
div-inv99.5%
expm1-log1p-u97.0%
expm1-udef88.9%
Applied egg-rr82.4%
expm1-def90.4%
expm1-log1p92.2%
*-commutative92.2%
associate-*r*92.2%
*-commutative92.2%
Simplified92.2%
Final simplification92.2%
(FPCore (k n) :precision binary64 (sqrt (* (* n PI) (/ 2.0 k))))
double code(double k, double n) {
return sqrt(((n * ((double) M_PI)) * (2.0 / k)));
}
public static double code(double k, double n) {
return Math.sqrt(((n * Math.PI) * (2.0 / k)));
}
def code(k, n): return math.sqrt(((n * math.pi) * (2.0 / k)))
function code(k, n) return sqrt(Float64(Float64(n * pi) * Float64(2.0 / k))) end
function tmp = code(k, n) tmp = sqrt(((n * pi) * (2.0 / k))); end
code[k_, n_] := N[Sqrt[N[(N[(n * Pi), $MachinePrecision] * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(n \cdot \pi\right) \cdot \frac{2}{k}}
\end{array}
Initial program 99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
div-inv99.5%
expm1-log1p-u97.0%
expm1-udef88.9%
Applied egg-rr82.4%
expm1-def90.4%
expm1-log1p92.2%
*-commutative92.2%
associate-*r*92.2%
*-commutative92.2%
Simplified92.2%
add-cbrt-cube82.6%
add-sqr-sqrt82.6%
*-commutative82.6%
*-commutative82.6%
Applied egg-rr82.6%
*-commutative82.6%
unpow1/282.6%
pow-plus82.7%
*-commutative82.7%
associate-*l*82.7%
metadata-eval82.7%
Simplified82.7%
pow1/380.9%
Applied egg-rr80.9%
Taylor expanded in k around 0 25.5%
Simplified35.9%
Final simplification35.9%
(FPCore (k n) :precision binary64 (sqrt (/ (* n (* 2.0 PI)) k)))
double code(double k, double n) {
return sqrt(((n * (2.0 * ((double) M_PI))) / k));
}
public static double code(double k, double n) {
return Math.sqrt(((n * (2.0 * Math.PI)) / k));
}
def code(k, n): return math.sqrt(((n * (2.0 * math.pi)) / k))
function code(k, n) return sqrt(Float64(Float64(n * Float64(2.0 * pi)) / k)) end
function tmp = code(k, n) tmp = sqrt(((n * (2.0 * pi)) / k)); end
code[k_, n_] := N[Sqrt[N[(N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{n \cdot \left(2 \cdot \pi\right)}{k}}
\end{array}
Initial program 99.4%
*-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
div-inv99.5%
expm1-log1p-u97.0%
expm1-udef88.9%
Applied egg-rr82.4%
expm1-def90.4%
expm1-log1p92.2%
*-commutative92.2%
associate-*r*92.2%
*-commutative92.2%
Simplified92.2%
pow-to-exp89.9%
*-commutative89.9%
Applied egg-rr89.9%
Taylor expanded in k around 0 35.9%
*-commutative35.9%
associate-*r*35.9%
Simplified35.9%
Final simplification35.9%
herbie shell --seed 2023257
(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))))