
(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 (* PI n)))) (/ (sqrt t_0) (* (sqrt k) (pow t_0 (* k 0.5))))))
double code(double k, double n) {
double t_0 = 2.0 * (((double) M_PI) * n);
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 * (Math.PI * n);
return Math.sqrt(t_0) / (Math.sqrt(k) * Math.pow(t_0, (k * 0.5)));
}
def code(k, n): t_0 = 2.0 * (math.pi * n) return math.sqrt(t_0) / (math.sqrt(k) * math.pow(t_0, (k * 0.5)))
function code(k, n) t_0 = Float64(2.0 * Float64(pi * n)) return Float64(sqrt(t_0) / Float64(sqrt(k) * (t_0 ^ Float64(k * 0.5)))) end
function tmp = code(k, n) t_0 = 2.0 * (pi * n); tmp = sqrt(t_0) / (sqrt(k) * (t_0 ^ (k * 0.5))); end
code[k_, n_] := Block[{t$95$0 = N[(2.0 * N[(Pi * 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 := 2 \cdot \left(\pi \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.6%
*-un-lft-identity99.6%
associate-*r*99.6%
div-sub99.6%
metadata-eval99.6%
pow-div99.7%
pow1/299.7%
associate-/l/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (if (<= k 6.2e-45) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (sqrt (/ (pow (* 2.0 (* PI n)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 6.2e-45) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = sqrt((pow((2.0 * (((double) M_PI) * n)), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 6.2e-45) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = Math.sqrt((Math.pow((2.0 * (Math.PI * n)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 6.2e-45: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / k))) else: tmp = math.sqrt((math.pow((2.0 * (math.pi * n)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 6.2e-45) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = sqrt(Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 6.2e-45) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = sqrt((((2.0 * (pi * n)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 6.2e-45], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(2.0 * N[(Pi * n), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 6.2 \cdot 10^{-45}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(2 \cdot \left(\pi \cdot n\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 6.2000000000000002e-45Initial program 99.3%
add-sqr-sqrt98.9%
sqrt-unprod76.5%
*-commutative76.5%
associate-*r*76.5%
div-sub76.5%
metadata-eval76.5%
div-inv76.6%
*-commutative76.6%
Applied egg-rr76.6%
Simplified76.9%
Taylor expanded in k around 0 76.9%
pow1/276.9%
associate-/l*76.8%
associate-*r*76.8%
*-commutative76.8%
metadata-eval76.8%
associate-*l*76.8%
unpow-prod-down99.5%
metadata-eval99.5%
pow1/299.5%
metadata-eval99.5%
Applied egg-rr99.5%
unpow1/299.5%
Simplified99.5%
if 6.2000000000000002e-45 < k Initial program 99.7%
add-sqr-sqrt99.6%
sqrt-unprod99.7%
*-commutative99.7%
associate-*r*99.7%
div-sub99.7%
metadata-eval99.7%
div-inv99.7%
*-commutative99.7%
Applied egg-rr99.7%
Simplified99.7%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 8.2e+186) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (pow (* (pow (* n (/ PI k)) 2.0) 4.0) 0.25)))
double code(double k, double n) {
double tmp;
if (k <= 8.2e+186) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = pow((pow((n * (((double) M_PI) / k)), 2.0) * 4.0), 0.25);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 8.2e+186) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = Math.pow((Math.pow((n * (Math.PI / k)), 2.0) * 4.0), 0.25);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 8.2e+186: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / k))) else: tmp = math.pow((math.pow((n * (math.pi / k)), 2.0) * 4.0), 0.25) return tmp
function code(k, n) tmp = 0.0 if (k <= 8.2e+186) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = Float64((Float64(n * Float64(pi / k)) ^ 2.0) * 4.0) ^ 0.25; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 8.2e+186) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = (((n * (pi / k)) ^ 2.0) * 4.0) ^ 0.25; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 8.2e+186], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[(N[Power[N[(n * N[(Pi / k), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * 4.0), $MachinePrecision], 0.25], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 8.2 \cdot 10^{+186}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(n \cdot \frac{\pi}{k}\right)}^{2} \cdot 4\right)}^{0.25}\\
\end{array}
\end{array}
if k < 8.2e186Initial program 99.4%
add-sqr-sqrt99.1%
sqrt-unprod86.8%
*-commutative86.8%
associate-*r*86.8%
div-sub86.8%
metadata-eval86.8%
div-inv86.8%
*-commutative86.8%
Applied egg-rr86.9%
Simplified87.0%
Taylor expanded in k around 0 51.8%
pow1/251.8%
associate-/l*51.8%
associate-*r*51.8%
*-commutative51.8%
metadata-eval51.8%
associate-*l*51.8%
unpow-prod-down64.2%
metadata-eval64.2%
pow1/264.2%
metadata-eval64.2%
Applied egg-rr64.2%
unpow1/264.3%
Simplified64.3%
if 8.2e186 < k Initial program 100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
*-commutative100.0%
associate-*r*100.0%
div-sub100.0%
metadata-eval100.0%
div-inv100.0%
*-commutative100.0%
Applied egg-rr100.0%
Simplified100.0%
Taylor expanded in k around 0 2.7%
pow1/22.7%
associate-/l*2.7%
associate-*r*2.7%
*-commutative2.7%
metadata-eval2.7%
pow-sqr2.7%
pow-prod-down15.0%
Applied egg-rr15.0%
Final simplification52.3%
(FPCore (k n) :precision binary64 (if (<= k 4.7e+150) (* (sqrt n) (sqrt (* 2.0 (/ PI k)))) (pow (pow (* 2.0 (/ (* PI n) k)) 3.0) 0.16666666666666666)))
double code(double k, double n) {
double tmp;
if (k <= 4.7e+150) {
tmp = sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
} else {
tmp = pow(pow((2.0 * ((((double) M_PI) * n) / k)), 3.0), 0.16666666666666666);
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 4.7e+150) {
tmp = Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
} else {
tmp = Math.pow(Math.pow((2.0 * ((Math.PI * n) / k)), 3.0), 0.16666666666666666);
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 4.7e+150: tmp = math.sqrt(n) * math.sqrt((2.0 * (math.pi / k))) else: tmp = math.pow(math.pow((2.0 * ((math.pi * n) / k)), 3.0), 0.16666666666666666) return tmp
function code(k, n) tmp = 0.0 if (k <= 4.7e+150) tmp = Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))); else tmp = (Float64(2.0 * Float64(Float64(pi * n) / k)) ^ 3.0) ^ 0.16666666666666666; end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 4.7e+150) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); else tmp = ((2.0 * ((pi * n) / k)) ^ 3.0) ^ 0.16666666666666666; end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 4.7e+150], N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(2.0 * N[(N[(Pi * n), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 0.16666666666666666], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 4.7 \cdot 10^{+150}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(2 \cdot \frac{\pi \cdot n}{k}\right)}^{3}\right)}^{0.16666666666666666}\\
\end{array}
\end{array}
if k < 4.70000000000000004e150Initial program 99.3%
add-sqr-sqrt99.1%
sqrt-unprod85.9%
*-commutative85.9%
associate-*r*85.9%
div-sub85.9%
metadata-eval85.9%
div-inv86.0%
*-commutative86.0%
Applied egg-rr86.0%
Simplified86.2%
Taylor expanded in k around 0 55.1%
pow1/255.1%
associate-/l*55.0%
associate-*r*55.0%
*-commutative55.0%
metadata-eval55.0%
associate-*l*55.0%
unpow-prod-down68.3%
metadata-eval68.3%
pow1/268.3%
metadata-eval68.3%
Applied egg-rr68.3%
unpow1/268.3%
Simplified68.3%
if 4.70000000000000004e150 < k Initial program 100.0%
add-sqr-sqrt100.0%
sqrt-unprod100.0%
*-commutative100.0%
associate-*r*100.0%
div-sub100.0%
metadata-eval100.0%
div-inv100.0%
*-commutative100.0%
Applied egg-rr100.0%
Simplified100.0%
Taylor expanded in k around 0 2.7%
associate-*r/2.7%
associate-*r*2.7%
*-commutative2.7%
Simplified2.7%
pow1/22.7%
associate-*r*2.7%
metadata-eval2.7%
pow-pow6.5%
sqr-pow6.5%
pow-prod-down20.7%
pow-prod-up20.7%
metadata-eval20.7%
associate-*r/20.7%
*-commutative20.7%
associate-/l*20.7%
metadata-eval20.7%
Applied egg-rr20.7%
associate-*r*20.7%
associate-*r/20.7%
associate-*l/20.7%
*-commutative20.7%
Simplified20.7%
Final simplification54.6%
(FPCore (k n) :precision binary64 (/ (pow (* 2.0 (* PI n)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((2.0 * (((double) M_PI) * n)), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((2.0 * (Math.PI * n)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((2.0 * (math.pi * n)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(2.0 * Float64(pi * n)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((2.0 * (pi * n)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(2.0 * N[(Pi * n), $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(\pi \cdot n\right)\right)}^{\left(0.5 - \frac{k}{2}\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
associate-*l/99.6%
*-lft-identity99.6%
associate-*l*99.6%
div-sub99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (sqrt n) (sqrt (* 2.0 (/ PI k)))))
double code(double k, double n) {
return sqrt(n) * sqrt((2.0 * (((double) M_PI) / k)));
}
public static double code(double k, double n) {
return Math.sqrt(n) * Math.sqrt((2.0 * (Math.PI / k)));
}
def code(k, n): return math.sqrt(n) * math.sqrt((2.0 * (math.pi / k)))
function code(k, n) return Float64(sqrt(n) * sqrt(Float64(2.0 * Float64(pi / k)))) end
function tmp = code(k, n) tmp = sqrt(n) * sqrt((2.0 * (pi / k))); end
code[k_, n_] := N[(N[Sqrt[n], $MachinePrecision] * N[Sqrt[N[(2.0 * N[(Pi / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{n} \cdot \sqrt{2 \cdot \frac{\pi}{k}}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
*-commutative90.0%
associate-*r*90.0%
div-sub90.0%
metadata-eval90.0%
div-inv90.0%
*-commutative90.0%
Applied egg-rr90.1%
Simplified90.2%
Taylor expanded in k around 0 39.9%
pow1/239.9%
associate-/l*39.9%
associate-*r*39.9%
*-commutative39.9%
metadata-eval39.9%
associate-*l*39.9%
unpow-prod-down49.4%
metadata-eval49.4%
pow1/249.4%
metadata-eval49.4%
Applied egg-rr49.4%
unpow1/249.4%
Simplified49.4%
Final simplification49.4%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ k (* n (* 2.0 PI))))))
double code(double k, double n) {
return 1.0 / sqrt((k / (n * (2.0 * ((double) M_PI)))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((k / (n * (2.0 * Math.PI))));
}
def code(k, n): return 1.0 / math.sqrt((k / (n * (2.0 * math.pi))))
function code(k, n) return Float64(1.0 / sqrt(Float64(k / Float64(n * Float64(2.0 * pi))))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((k / (n * (2.0 * pi)))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(k / N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{k}{n \cdot \left(2 \cdot \pi\right)}}}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
*-commutative90.0%
associate-*r*90.0%
div-sub90.0%
metadata-eval90.0%
div-inv90.0%
*-commutative90.0%
Applied egg-rr90.1%
Simplified90.2%
Taylor expanded in k around 0 39.9%
associate-*r/39.9%
associate-*r*39.9%
*-commutative39.9%
Simplified39.9%
associate-*r*39.9%
associate-*r/39.9%
*-commutative39.9%
associate-*r/39.9%
associate-*r*39.9%
sqrt-div49.4%
clear-num49.3%
sqrt-undiv40.6%
associate-*r*40.6%
Applied egg-rr40.6%
Final simplification40.6%
(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(Float64(pi * 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[(N[(Pi * n), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi \cdot n}{k}}
\end{array}
Initial program 99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
*-commutative90.0%
associate-*r*90.0%
div-sub90.0%
metadata-eval90.0%
div-inv90.0%
*-commutative90.0%
Applied egg-rr90.1%
Simplified90.2%
Taylor expanded in k around 0 39.9%
Final simplification39.9%
herbie shell --seed 2024053
(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))))