
(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 (* PI (* 2.0 n)))) (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = ((double) M_PI) * (2.0 * n);
return sqrt(t_0) / (sqrt(k) * pow(t_0, (k * 0.5)));
}
public static double code(double k, double n) {
double t_0 = Math.PI * (2.0 * n);
return Math.sqrt(t_0) / (Math.sqrt(k) * Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = math.pi * (2.0 * n) return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(pi * Float64(2.0 * n)) return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = pi * (2.0 * n); tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(Pi * N[(2.0 * n), $MachinePrecision]), $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 := \pi \cdot \left(2 \cdot n\right)\\
\frac{\sqrt{t\_0}}{\sqrt{k} \cdot {t\_0}^{\left(k \cdot 0.5\right)}}
\end{array}
\end{array}
Initial program 99.5%
associate-*l/99.5%
*-un-lft-identity99.5%
*-commutative99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
pow-sub99.7%
pow1/299.7%
associate-/l/99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
Applied egg-rr99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (* (pow (sqrt (* PI (* 2.0 n))) (- 1.0 k)) (pow k -0.5)))
double code(double k, double n) {
return pow(sqrt((((double) M_PI) * (2.0 * n))), (1.0 - k)) * pow(k, -0.5);
}
public static double code(double k, double n) {
return Math.pow(Math.sqrt((Math.PI * (2.0 * n))), (1.0 - k)) * Math.pow(k, -0.5);
}
def code(k, n): return math.pow(math.sqrt((math.pi * (2.0 * n))), (1.0 - k)) * math.pow(k, -0.5)
function code(k, n) return Float64((sqrt(Float64(pi * Float64(2.0 * n))) ^ Float64(1.0 - k)) * (k ^ -0.5)) end
function tmp = code(k, n) tmp = (sqrt((pi * (2.0 * n))) ^ (1.0 - k)) * (k ^ -0.5); end
code[k_, n_] := N[(N[Power[N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] * N[Power[k, -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\sqrt{\pi \cdot \left(2 \cdot n\right)}\right)}^{\left(1 - k\right)} \cdot {k}^{-0.5}
\end{array}
Initial program 99.5%
associate-*l/99.5%
*-un-lft-identity99.5%
*-commutative99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
pow-sub99.7%
pow1/299.7%
associate-/l/99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
Applied egg-rr99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*l*99.7%
*-commutative99.7%
Simplified99.7%
*-un-lft-identity99.7%
frac-times99.7%
metadata-eval99.7%
sqrt-div99.7%
pow199.7%
pow-unpow99.7%
pow1/299.7%
pow-sub99.5%
*-commutative99.5%
sqrt-div99.5%
metadata-eval99.5%
inv-pow99.5%
sqrt-pow299.6%
metadata-eval99.6%
metadata-eval99.6%
pow-pow99.3%
Applied egg-rr99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 2e-49) (* (sqrt (* 2.0 (/ PI k))) (sqrt n)) (sqrt (/ (pow (* PI (* 2.0 n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 2e-49) {
tmp = sqrt((2.0 * (((double) M_PI) / k))) * sqrt(n);
} else {
tmp = sqrt((pow((((double) M_PI) * (2.0 * n)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 2e-49) {
tmp = Math.sqrt((2.0 * (Math.PI / k))) * Math.sqrt(n);
} else {
tmp = Math.sqrt((Math.pow((Math.PI * (2.0 * n)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 2e-49: tmp = math.sqrt((2.0 * (math.pi / k))) * math.sqrt(n) else: tmp = math.sqrt((math.pow((math.pi * (2.0 * n)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 2e-49) tmp = Float64(sqrt(Float64(2.0 * Float64(pi / k))) * sqrt(n)); else tmp = sqrt(Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 2e-49) tmp = sqrt((2.0 * (pi / k))) * sqrt(n); else tmp = sqrt((((pi * (2.0 * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 2e-49], N[(N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2 \cdot 10^{-49}:\\
\;\;\;\;\sqrt{2 \cdot \frac{\pi}{k}} \cdot \sqrt{n}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1.99999999999999987e-49Initial program 99.3%
Taylor expanded in k around 0 99.1%
expm1-log1p-u93.7%
expm1-udef72.7%
associate-*l/72.7%
*-un-lft-identity72.7%
sqrt-unprod72.7%
*-commutative72.7%
*-commutative72.7%
sqrt-undiv54.2%
associate-*r*54.2%
*-commutative54.2%
*-commutative54.2%
Applied egg-rr54.2%
expm1-def75.3%
expm1-log1p79.1%
*-rgt-identity79.1%
associate-*r/79.0%
associate-*r*79.0%
*-commutative79.0%
*-commutative79.0%
associate-*l*79.0%
*-commutative79.0%
associate-*r*79.0%
associate-*l/79.2%
*-lft-identity79.2%
Simplified79.2%
associate-*r*79.2%
sqrt-prod99.6%
Applied egg-rr99.6%
if 1.99999999999999987e-49 < k Initial program 99.6%
associate-*l/99.6%
*-un-lft-identity99.6%
*-commutative99.6%
associate-*r*99.6%
div-sub99.6%
metadata-eval99.6%
pow-sub99.9%
pow1/299.9%
associate-/l/99.9%
associate-*r*99.9%
*-commutative99.9%
associate-*l*99.9%
Applied egg-rr99.9%
associate-*r*99.9%
*-commutative99.9%
associate-*l*99.9%
associate-*r*99.9%
*-commutative99.9%
associate-*l*99.9%
*-commutative99.9%
Simplified99.9%
*-un-lft-identity99.9%
frac-times99.9%
metadata-eval99.9%
sqrt-div99.9%
pow199.9%
pow-unpow99.9%
pow1/299.9%
pow-sub99.6%
*-commutative99.6%
sqrt-div99.6%
metadata-eval99.6%
inv-pow99.6%
sqrt-pow299.6%
metadata-eval99.6%
metadata-eval99.6%
pow-pow99.6%
Applied egg-rr99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
Simplified99.6%
add-sqr-sqrt99.6%
sqrt-unprod99.6%
swap-sqr99.6%
pow-prod-down99.6%
add-sqr-sqrt99.6%
associate-*l*99.6%
pow-prod-up99.6%
metadata-eval99.6%
inv-pow99.6%
Applied egg-rr99.6%
associate-*r/99.6%
*-rgt-identity99.6%
associate-*r*99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (pow k -0.5) (pow (* 2.0 (* PI n)) (+ 0.5 (* k -0.5)))))
double code(double k, double n) {
return pow(k, -0.5) * pow((2.0 * (((double) M_PI) * n)), (0.5 + (k * -0.5)));
}
public static double code(double k, double n) {
return Math.pow(k, -0.5) * Math.pow((2.0 * (Math.PI * n)), (0.5 + (k * -0.5)));
}
def code(k, n): return math.pow(k, -0.5) * math.pow((2.0 * (math.pi * n)), (0.5 + (k * -0.5)))
function code(k, n) return Float64((k ^ -0.5) * (Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 + Float64(k * -0.5)))) end
function tmp = code(k, n) tmp = (k ^ -0.5) * ((2.0 * (pi * n)) ^ (0.5 + (k * -0.5))); end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] * N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(k * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{k}^{-0.5} \cdot {\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(0.5 + k \cdot -0.5\right)}
\end{array}
Initial program 99.5%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.4%
pow-sqr99.5%
*-commutative99.5%
associate-*l*99.5%
associate-*r/99.5%
*-commutative99.5%
associate-/l*99.5%
metadata-eval99.5%
/-rgt-identity99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
div-inv99.5%
associate-*r*99.5%
*-commutative99.5%
associate-*l*99.5%
sub-neg99.5%
div-inv99.5%
metadata-eval99.5%
distribute-rgt-neg-in99.5%
metadata-eval99.5%
inv-pow99.5%
sqrt-pow299.5%
metadata-eval99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (pow (* PI (* 2.0 n)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((((double) M_PI) * (2.0 * n)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((Math.PI * (2.0 * n)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((math.pi * (2.0 * n)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(pi * Float64(2.0 * n)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((pi * (2.0 * n)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\pi \cdot \left(2 \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
associate-*l/99.5%
*-lft-identity99.5%
sqr-pow99.4%
pow-sqr99.5%
*-commutative99.5%
associate-*l*99.5%
associate-*r/99.5%
*-commutative99.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 (* 2.0 (/ PI k))) (sqrt n)))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) / k))) * sqrt(n);
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI / k))) * Math.sqrt(n);
}
def code(k, n): return math.sqrt((2.0 * (math.pi / k))) * math.sqrt(n)
function code(k, n) return Float64(sqrt(Float64(2.0 * Float64(pi / k))) * sqrt(n)) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi / k))) * sqrt(n); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi}{k}} \cdot \sqrt{n}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 48.8%
expm1-log1p-u46.4%
expm1-udef42.2%
associate-*l/42.2%
*-un-lft-identity42.2%
sqrt-unprod42.2%
*-commutative42.2%
*-commutative42.2%
sqrt-undiv34.2%
associate-*r*34.2%
*-commutative34.2%
*-commutative34.2%
Applied egg-rr34.2%
expm1-def38.5%
expm1-log1p40.2%
*-rgt-identity40.2%
associate-*r/40.1%
associate-*r*40.1%
*-commutative40.1%
*-commutative40.1%
associate-*l*40.1%
*-commutative40.1%
associate-*r*40.1%
associate-*l/40.2%
*-lft-identity40.2%
Simplified40.2%
associate-*r*40.2%
sqrt-prod49.0%
Applied egg-rr49.0%
Final simplification49.0%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (* PI (/ n k)))))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) * (n / k))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI * (n / k))));
}
def code(k, n): return math.sqrt((2.0 * (math.pi * (n / k))))
function code(k, n) return sqrt(Float64(2.0 * Float64(pi * Float64(n / k)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi * (n / k)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(Pi * N[(n / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \left(\pi \cdot \frac{n}{k}\right)}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 48.8%
expm1-log1p-u46.4%
expm1-udef42.2%
associate-*l/42.2%
*-un-lft-identity42.2%
sqrt-unprod42.2%
*-commutative42.2%
*-commutative42.2%
sqrt-undiv34.2%
associate-*r*34.2%
*-commutative34.2%
*-commutative34.2%
Applied egg-rr34.2%
expm1-def38.5%
expm1-log1p40.2%
*-rgt-identity40.2%
associate-*r/40.1%
associate-*r*40.1%
*-commutative40.1%
*-commutative40.1%
associate-*l*40.1%
*-commutative40.1%
associate-*r*40.1%
associate-*l/40.2%
*-lft-identity40.2%
Simplified40.2%
Taylor expanded in k around 0 40.2%
associate-*l/40.2%
Simplified40.2%
Final simplification40.2%
(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.5%
Taylor expanded in k around 0 48.8%
expm1-log1p-u46.4%
expm1-udef42.2%
associate-*l/42.2%
*-un-lft-identity42.2%
sqrt-unprod42.2%
*-commutative42.2%
*-commutative42.2%
sqrt-undiv34.2%
associate-*r*34.2%
*-commutative34.2%
*-commutative34.2%
Applied egg-rr34.2%
expm1-def38.5%
expm1-log1p40.2%
*-rgt-identity40.2%
associate-*r/40.1%
associate-*r*40.1%
*-commutative40.1%
*-commutative40.1%
associate-*l*40.1%
*-commutative40.1%
associate-*r*40.1%
associate-*l/40.2%
*-lft-identity40.2%
Simplified40.2%
Final simplification40.2%
herbie shell --seed 2024026
(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))))