
(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 10 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))) (/ (sqrt t_0) (sqrt (* k (pow t_0 k))))))
double code(double k, double n) {
double t_0 = (n * 2.0) * ((double) M_PI);
return sqrt(t_0) / sqrt((k * pow(t_0, k)));
}
public static double code(double k, double n) {
double t_0 = (n * 2.0) * Math.PI;
return Math.sqrt(t_0) / Math.sqrt((k * Math.pow(t_0, k)));
}
def code(k, n): t_0 = (n * 2.0) * math.pi return math.sqrt(t_0) / math.sqrt((k * math.pow(t_0, k)))
function code(k, n) t_0 = Float64(Float64(n * 2.0) * pi) return Float64(sqrt(t_0) / sqrt(Float64(k * (t_0 ^ k)))) end
function tmp = code(k, n) t_0 = (n * 2.0) * pi; tmp = sqrt(t_0) / sqrt((k * (t_0 ^ k))); end
code[k_, n_] := Block[{t$95$0 = N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] / N[Sqrt[N[(k * N[Power[t$95$0, k], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(n \cdot 2\right) \cdot \pi\\
\frac{\sqrt{t\_0}}{\sqrt{k \cdot {t\_0}^{k}}}
\end{array}
\end{array}
Initial program 99.1%
associate-*l/99.1%
*-un-lft-identity99.1%
associate-*r*99.1%
div-sub99.1%
metadata-eval99.1%
pow-div99.3%
pow1/299.3%
associate-/l/99.3%
div-inv99.3%
metadata-eval99.3%
Applied egg-rr99.3%
associate-/l/99.3%
unpow1/299.3%
metadata-eval99.3%
pow-sqr99.1%
fabs-sqr99.1%
pow-sqr99.3%
metadata-eval99.3%
unpow1/299.3%
fabs-neg99.3%
neg-mul-199.3%
rem-square-sqrt0.0%
unpow1/20.0%
metadata-eval0.0%
pow-sqr0.0%
unswap-sqr0.0%
fabs-sqr0.0%
unswap-sqr0.0%
rem-square-sqrt25.2%
pow-sqr25.2%
metadata-eval25.2%
unpow1/225.2%
Simplified99.3%
div-inv99.2%
*-commutative99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.2%
pow1/299.2%
pow-unpow99.2%
pow-prod-down99.2%
*-commutative99.2%
associate-*r*99.2%
*-commutative99.2%
associate-*r*99.2%
Applied egg-rr99.2%
associate-*r/99.3%
*-commutative99.3%
*-lft-identity99.3%
*-commutative99.3%
associate-*l*99.3%
unpow1/299.3%
*-commutative99.3%
associate-*l*99.3%
Simplified99.3%
(FPCore (k n) :precision binary64 (/ (pow k -0.5) (pow (* (* n 2.0) PI) (fma k 0.5 -0.5))))
double code(double k, double n) {
return pow(k, -0.5) / pow(((n * 2.0) * ((double) M_PI)), fma(k, 0.5, -0.5));
}
function code(k, n) return Float64((k ^ -0.5) / (Float64(Float64(n * 2.0) * pi) ^ fma(k, 0.5, -0.5))) end
code[k_, n_] := N[(N[Power[k, -0.5], $MachinePrecision] / N[Power[N[(N[(n * 2.0), $MachinePrecision] * Pi), $MachinePrecision], N[(k * 0.5 + -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{k}^{-0.5}}{{\left(\left(n \cdot 2\right) \cdot \pi\right)}^{\left(\mathsf{fma}\left(k, 0.5, -0.5\right)\right)}}
\end{array}
Initial program 99.1%
associate-*l/99.1%
*-un-lft-identity99.1%
associate-*r*99.1%
div-sub99.1%
metadata-eval99.1%
pow-div99.3%
pow1/299.3%
associate-/l/99.3%
div-inv99.3%
metadata-eval99.3%
Applied egg-rr99.3%
associate-/l/99.3%
unpow1/299.3%
metadata-eval99.3%
pow-sqr99.1%
fabs-sqr99.1%
pow-sqr99.3%
metadata-eval99.3%
unpow1/299.3%
fabs-neg99.3%
neg-mul-199.3%
rem-square-sqrt0.0%
unpow1/20.0%
metadata-eval0.0%
pow-sqr0.0%
unswap-sqr0.0%
fabs-sqr0.0%
unswap-sqr0.0%
rem-square-sqrt25.2%
pow-sqr25.2%
metadata-eval25.2%
unpow1/225.2%
Simplified99.3%
clear-num99.2%
inv-pow99.2%
Applied egg-rr99.0%
unpow-199.0%
/-rgt-identity99.0%
*-commutative99.0%
associate-*l*99.0%
fmm-def99.0%
metadata-eval99.0%
Simplified99.0%
*-un-lft-identity99.0%
associate-/r*99.0%
pow1/299.0%
pow-flip99.1%
metadata-eval99.1%
associate-*l*99.1%
Applied egg-rr99.1%
*-lft-identity99.1%
associate-*r*99.1%
Simplified99.1%
(FPCore (k n) :precision binary64 (if (<= k 3.6e-11) (/ (sqrt (* n 2.0)) (sqrt (/ k PI))) (sqrt (/ (pow (* 2.0 (* n PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 3.6e-11) {
tmp = sqrt((n * 2.0)) / sqrt((k / ((double) M_PI)));
} 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 <= 3.6e-11) {
tmp = Math.sqrt((n * 2.0)) / Math.sqrt((k / Math.PI));
} 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 <= 3.6e-11: tmp = math.sqrt((n * 2.0)) / math.sqrt((k / math.pi)) 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 <= 3.6e-11) tmp = Float64(sqrt(Float64(n * 2.0)) / sqrt(Float64(k / pi))); else tmp = sqrt(Float64((Float64(2.0 * Float64(n * pi)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 3.6e-11) tmp = sqrt((n * 2.0)) / sqrt((k / pi)); else tmp = sqrt((((2.0 * (n * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 3.6e-11], N[(N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(2.0 * N[(n * Pi), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 3.6 \cdot 10^{-11}:\\
\;\;\;\;\frac{\sqrt{n \cdot 2}}{\sqrt{\frac{k}{\pi}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(2 \cdot \left(n \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 3.59999999999999985e-11Initial program 98.4%
Taylor expanded in k around 0 71.2%
*-commutative71.2%
associate-/l*71.2%
Simplified71.2%
pow171.2%
*-commutative71.2%
sqrt-unprod71.6%
Applied egg-rr71.6%
unpow171.6%
*-commutative71.6%
associate-*r*71.6%
*-commutative71.6%
Simplified71.6%
Taylor expanded in n around 0 71.5%
associate-*r/71.5%
associate-*r*71.5%
*-commutative71.5%
associate-*l/71.5%
associate-/r/71.5%
associate-/l*71.5%
Simplified71.5%
associate-*r/71.5%
sqrt-div98.5%
Applied egg-rr98.5%
if 3.59999999999999985e-11 < k Initial program 99.7%
Applied egg-rr99.7%
distribute-rgt-in99.7%
metadata-eval99.7%
associate-*l*99.7%
metadata-eval99.7%
*-commutative99.7%
neg-mul-199.7%
sub-neg99.7%
*-commutative99.7%
Simplified99.7%
(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.1%
associate-*l/99.1%
*-lft-identity99.1%
associate-*l*99.1%
div-sub99.1%
metadata-eval99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (k n) :precision binary64 (/ (sqrt (* n 2.0)) (sqrt (/ k PI))))
double code(double k, double n) {
return sqrt((n * 2.0)) / sqrt((k / ((double) M_PI)));
}
public static double code(double k, double n) {
return Math.sqrt((n * 2.0)) / Math.sqrt((k / Math.PI));
}
def code(k, n): return math.sqrt((n * 2.0)) / math.sqrt((k / math.pi))
function code(k, n) return Float64(sqrt(Float64(n * 2.0)) / sqrt(Float64(k / pi))) end
function tmp = code(k, n) tmp = sqrt((n * 2.0)) / sqrt((k / pi)); end
code[k_, n_] := N[(N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n \cdot 2}}{\sqrt{\frac{k}{\pi}}}
\end{array}
Initial program 99.1%
Taylor expanded in k around 0 37.9%
*-commutative37.9%
associate-/l*37.9%
Simplified37.9%
pow137.9%
*-commutative37.9%
sqrt-unprod38.1%
Applied egg-rr38.1%
unpow138.1%
*-commutative38.1%
associate-*r*38.1%
*-commutative38.1%
Simplified38.1%
Taylor expanded in n around 0 38.0%
associate-*r/38.0%
associate-*r*38.0%
*-commutative38.0%
associate-*l/38.1%
associate-/r/38.1%
associate-/l*38.0%
Simplified38.0%
associate-*r/38.1%
sqrt-div51.6%
Applied egg-rr51.6%
(FPCore (k n) :precision binary64 (* (sqrt (* n 2.0)) (sqrt (/ PI k))))
double code(double k, double n) {
return sqrt((n * 2.0)) * sqrt((((double) M_PI) / k));
}
public static double code(double k, double n) {
return Math.sqrt((n * 2.0)) * Math.sqrt((Math.PI / k));
}
def code(k, n): return math.sqrt((n * 2.0)) * math.sqrt((math.pi / k))
function code(k, n) return Float64(sqrt(Float64(n * 2.0)) * sqrt(Float64(pi / k))) end
function tmp = code(k, n) tmp = sqrt((n * 2.0)) * sqrt((pi / k)); end
code[k_, n_] := N[(N[Sqrt[N[(n * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n \cdot 2} \cdot \sqrt{\frac{\pi}{k}}
\end{array}
Initial program 99.1%
Taylor expanded in k around 0 37.9%
*-commutative37.9%
associate-/l*37.9%
Simplified37.9%
pow137.9%
*-commutative37.9%
sqrt-unprod38.1%
Applied egg-rr38.1%
unpow138.1%
*-commutative38.1%
associate-*r*38.1%
*-commutative38.1%
Simplified38.1%
*-commutative38.1%
sqrt-prod51.6%
Applied egg-rr51.6%
Final simplification51.6%
(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.1%
Taylor expanded in k around 0 37.9%
*-commutative37.9%
associate-/l*37.9%
Simplified37.9%
pow137.9%
*-commutative37.9%
sqrt-unprod38.1%
Applied egg-rr38.1%
unpow138.1%
*-commutative38.1%
associate-*r*38.1%
*-commutative38.1%
Simplified38.1%
sqrt-prod51.6%
*-commutative51.6%
sqrt-prod51.5%
associate-*r*51.5%
*-commutative51.5%
associate-*r*51.5%
sqrt-unprod51.2%
Applied egg-rr51.2%
(FPCore (k n) :precision binary64 (pow (* 0.5 (/ (/ k PI) n)) -0.5))
double code(double k, double n) {
return pow((0.5 * ((k / ((double) M_PI)) / n)), -0.5);
}
public static double code(double k, double n) {
return Math.pow((0.5 * ((k / Math.PI) / n)), -0.5);
}
def code(k, n): return math.pow((0.5 * ((k / math.pi) / n)), -0.5)
function code(k, n) return Float64(0.5 * Float64(Float64(k / pi) / n)) ^ -0.5 end
function tmp = code(k, n) tmp = (0.5 * ((k / pi) / n)) ^ -0.5; end
code[k_, n_] := N[Power[N[(0.5 * N[(N[(k / Pi), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(0.5 \cdot \frac{\frac{k}{\pi}}{n}\right)}^{-0.5}
\end{array}
Initial program 99.1%
associate-/r/99.0%
associate-*r*99.0%
div-sub99.0%
metadata-eval99.0%
sub-neg99.0%
div-inv99.0%
metadata-eval99.0%
distribute-rgt-neg-in99.0%
metadata-eval99.0%
Applied egg-rr99.0%
Taylor expanded in k around 0 38.4%
associate-*r/38.4%
*-rgt-identity38.4%
Simplified38.4%
inv-pow38.4%
sqrt-undiv38.5%
sqrt-pow238.6%
div-inv38.6%
metadata-eval38.6%
metadata-eval38.6%
Applied egg-rr38.6%
*-commutative38.6%
associate-/r*38.6%
Simplified38.6%
Final simplification38.6%
(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 * 2.0) * Float64(pi / k))) end
function tmp = code(k, n) tmp = sqrt(((n * 2.0) * (pi / k))); end
code[k_, n_] := N[Sqrt[N[(N[(n * 2.0), $MachinePrecision] * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\left(n \cdot 2\right) \cdot \frac{\pi}{k}}
\end{array}
Initial program 99.1%
Taylor expanded in k around 0 37.9%
*-commutative37.9%
associate-/l*37.9%
Simplified37.9%
pow137.9%
*-commutative37.9%
sqrt-unprod38.1%
Applied egg-rr38.1%
unpow138.1%
*-commutative38.1%
associate-*r*38.1%
*-commutative38.1%
Simplified38.1%
(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(n * Float64(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 * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n \cdot \left(\pi \cdot \frac{2}{k}\right)}
\end{array}
Initial program 99.1%
Taylor expanded in k around 0 37.9%
*-commutative37.9%
associate-/l*37.9%
Simplified37.9%
pow137.9%
*-commutative37.9%
sqrt-unprod38.1%
Applied egg-rr38.1%
unpow138.1%
*-commutative38.1%
associate-*r*38.1%
*-commutative38.1%
Simplified38.1%
Taylor expanded in n around 0 38.0%
associate-*r/38.0%
associate-*r*38.0%
*-commutative38.0%
associate-*l/38.1%
associate-/r/38.1%
associate-/l*38.0%
Simplified38.0%
associate-/r/38.0%
Applied egg-rr38.0%
Final simplification38.0%
herbie shell --seed 2024163
(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))))