
(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 (* (* 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.5%
associate-*l/99.6%
*-un-lft-identity99.6%
associate-*r*99.6%
div-sub99.6%
metadata-eval99.6%
pow-div99.8%
pow1/299.8%
associate-/l/99.8%
div-inv99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*r*99.8%
associate-*r*99.8%
Simplified99.8%
div-inv99.7%
associate-*r*99.7%
add-sqr-sqrt99.5%
sqrt-unprod99.7%
swap-sqr99.7%
add-sqr-sqrt99.7%
pow-unpow99.7%
unpow1/299.7%
pow-unpow99.7%
unpow1/299.7%
add-sqr-sqrt99.7%
Applied egg-rr99.7%
associate-*r/99.8%
*-rgt-identity99.8%
*-commutative99.8%
associate-*r*99.8%
*-commutative99.8%
*-commutative99.8%
associate-*r*99.8%
*-commutative99.8%
Simplified99.8%
(FPCore (k n) :precision binary64 (if (<= k 5e-46) (* (sqrt (/ (* 2.0 PI) k)) (sqrt n)) (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 5e-46) {
tmp = sqrt(((2.0 * ((double) M_PI)) / k)) * sqrt(n);
} else {
tmp = sqrt((pow((n * (2.0 * ((double) M_PI))), (1.0 - k)) / k));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 5e-46) {
tmp = Math.sqrt(((2.0 * Math.PI) / k)) * Math.sqrt(n);
} else {
tmp = Math.sqrt((Math.pow((n * (2.0 * Math.PI)), (1.0 - k)) / k));
}
return tmp;
}
def code(k, n): tmp = 0 if k <= 5e-46: tmp = math.sqrt(((2.0 * math.pi) / k)) * math.sqrt(n) else: tmp = math.sqrt((math.pow((n * (2.0 * math.pi)), (1.0 - k)) / k)) return tmp
function code(k, n) tmp = 0.0 if (k <= 5e-46) tmp = Float64(sqrt(Float64(Float64(2.0 * pi) / k)) * sqrt(n)); else tmp = sqrt(Float64((Float64(n * Float64(2.0 * pi)) ^ Float64(1.0 - k)) / k)); end return tmp end
function tmp_2 = code(k, n) tmp = 0.0; if (k <= 5e-46) tmp = sqrt(((2.0 * pi) / k)) * sqrt(n); else tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 5e-46], N[(N[Sqrt[N[(N[(2.0 * Pi), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(1.0 - k), $MachinePrecision]], $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 5 \cdot 10^{-46}:\\
\;\;\;\;\sqrt{\frac{2 \cdot \pi}{k}} \cdot \sqrt{n}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 4.99999999999999992e-46Initial program 99.2%
Taylor expanded in k around 0 76.2%
associate-/l*76.2%
Simplified76.2%
pow176.2%
*-commutative76.2%
sqrt-unprod76.6%
Applied egg-rr76.6%
unpow176.6%
Simplified76.6%
clear-num76.4%
un-div-inv76.5%
Applied egg-rr76.5%
associate-*r/76.5%
*-commutative76.5%
div-inv76.4%
clear-num76.6%
div-inv76.4%
associate-*r*76.4%
*-commutative76.4%
associate-*r*76.4%
*-commutative76.4%
*-commutative76.4%
associate-*r*76.4%
*-commutative76.4%
div-inv76.4%
associate-*r*76.4%
*-commutative76.4%
sqrt-prod99.5%
associate-*r/99.6%
Applied egg-rr99.6%
if 4.99999999999999992e-46 < k Initial program 99.6%
add-sqr-sqrt99.6%
sqrt-unprod99.6%
*-commutative99.6%
associate-*r*99.6%
div-sub99.6%
metadata-eval99.6%
div-inv99.7%
*-commutative99.7%
Applied egg-rr99.7%
Simplified99.7%
Final simplification99.6%
(FPCore (k n) :precision binary64 (if (<= k 4.7e+89) (* (sqrt (/ (* 2.0 PI) k)) (sqrt n)) (sqrt (* 2.0 (+ -1.0 (fma n (/ PI k) 1.0))))))
double code(double k, double n) {
double tmp;
if (k <= 4.7e+89) {
tmp = sqrt(((2.0 * ((double) M_PI)) / k)) * sqrt(n);
} else {
tmp = sqrt((2.0 * (-1.0 + fma(n, (((double) M_PI) / k), 1.0))));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 4.7e+89) tmp = Float64(sqrt(Float64(Float64(2.0 * pi) / k)) * sqrt(n)); else tmp = sqrt(Float64(2.0 * Float64(-1.0 + fma(n, Float64(pi / k), 1.0)))); end return tmp end
code[k_, n_] := If[LessEqual[k, 4.7e+89], N[(N[Sqrt[N[(N[(2.0 * Pi), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(2.0 * N[(-1.0 + N[(n * N[(Pi / k), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 4.7 \cdot 10^{+89}:\\
\;\;\;\;\sqrt{\frac{2 \cdot \pi}{k}} \cdot \sqrt{n}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot \left(-1 + \mathsf{fma}\left(n, \frac{\pi}{k}, 1\right)\right)}\\
\end{array}
\end{array}
if k < 4.70000000000000022e89Initial program 99.2%
Taylor expanded in k around 0 53.4%
associate-/l*53.4%
Simplified53.4%
pow153.4%
*-commutative53.4%
sqrt-unprod53.6%
Applied egg-rr53.6%
unpow153.6%
Simplified53.6%
clear-num53.5%
un-div-inv53.6%
Applied egg-rr53.6%
associate-*r/53.6%
*-commutative53.6%
div-inv53.5%
clear-num53.6%
div-inv53.6%
associate-*r*53.6%
*-commutative53.6%
associate-*r*53.6%
*-commutative53.6%
*-commutative53.6%
associate-*r*53.6%
*-commutative53.6%
div-inv53.6%
associate-*r*53.6%
*-commutative53.6%
sqrt-prod66.9%
associate-*r/67.0%
Applied egg-rr67.0%
if 4.70000000000000022e89 < k Initial program 100.0%
Taylor expanded in k around 0 2.9%
associate-/l*2.9%
Simplified2.9%
pow12.9%
*-commutative2.9%
sqrt-unprod2.9%
Applied egg-rr2.9%
unpow12.9%
Simplified2.9%
expm1-log1p-u2.9%
expm1-undefine41.7%
Applied egg-rr41.7%
sub-neg41.7%
metadata-eval41.7%
+-commutative41.7%
log1p-undefine41.7%
rem-exp-log41.7%
+-commutative41.7%
fma-define41.7%
Simplified41.7%
Final simplification58.2%
(FPCore (k n) :precision binary64 (if (<= k 2.55e+241) (* (sqrt (/ (* 2.0 PI) k)) (sqrt n)) (cbrt (pow (* n (* PI (/ 2.0 k))) 1.5))))
double code(double k, double n) {
double tmp;
if (k <= 2.55e+241) {
tmp = sqrt(((2.0 * ((double) M_PI)) / k)) * sqrt(n);
} else {
tmp = cbrt(pow((n * (((double) M_PI) * (2.0 / k))), 1.5));
}
return tmp;
}
public static double code(double k, double n) {
double tmp;
if (k <= 2.55e+241) {
tmp = Math.sqrt(((2.0 * Math.PI) / k)) * Math.sqrt(n);
} else {
tmp = Math.cbrt(Math.pow((n * (Math.PI * (2.0 / k))), 1.5));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 2.55e+241) tmp = Float64(sqrt(Float64(Float64(2.0 * pi) / k)) * sqrt(n)); else tmp = cbrt((Float64(n * Float64(pi * Float64(2.0 / k))) ^ 1.5)); end return tmp end
code[k_, n_] := If[LessEqual[k, 2.55e+241], N[(N[Sqrt[N[(N[(2.0 * Pi), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(n * N[(Pi * N[(2.0 / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 2.55 \cdot 10^{+241}:\\
\;\;\;\;\sqrt{\frac{2 \cdot \pi}{k}} \cdot \sqrt{n}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{\left(n \cdot \left(\pi \cdot \frac{2}{k}\right)\right)}^{1.5}}\\
\end{array}
\end{array}
if k < 2.5500000000000001e241Initial program 99.4%
Taylor expanded in k around 0 40.7%
associate-/l*40.7%
Simplified40.7%
pow140.7%
*-commutative40.7%
sqrt-unprod40.9%
Applied egg-rr40.9%
unpow140.9%
Simplified40.9%
clear-num40.8%
un-div-inv40.8%
Applied egg-rr40.8%
associate-*r/40.8%
*-commutative40.8%
div-inv40.8%
clear-num40.9%
div-inv40.8%
associate-*r*40.8%
*-commutative40.8%
associate-*r*40.8%
*-commutative40.8%
*-commutative40.8%
associate-*r*40.8%
*-commutative40.8%
div-inv40.8%
associate-*r*40.8%
*-commutative40.8%
sqrt-prod50.9%
associate-*r/50.9%
Applied egg-rr50.9%
if 2.5500000000000001e241 < k Initial program 100.0%
Taylor expanded in k around 0 2.9%
associate-/l*2.9%
Simplified2.9%
pow12.9%
*-commutative2.9%
sqrt-unprod2.9%
Applied egg-rr2.9%
unpow12.9%
Simplified2.9%
add-cbrt-cube20.2%
pow1/320.2%
add-sqr-sqrt20.2%
pow120.2%
pow1/220.2%
pow-prod-up20.2%
associate-*r*20.2%
*-commutative20.2%
associate-*l*20.2%
metadata-eval20.2%
Applied egg-rr20.2%
unpow1/320.2%
associate-*r/20.2%
*-commutative20.2%
associate-/l*20.2%
Simplified20.2%
Final simplification46.9%
(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.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 (/ (* 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(Float64(2.0 * 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[(N[(2.0 * Pi), $MachinePrecision] / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[n], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{2 \cdot \pi}{k}} \cdot \sqrt{n}
\end{array}
Initial program 99.5%
Taylor expanded in k around 0 35.8%
associate-/l*35.8%
Simplified35.8%
pow135.8%
*-commutative35.8%
sqrt-unprod36.0%
Applied egg-rr36.0%
unpow136.0%
Simplified36.0%
clear-num35.9%
un-div-inv35.9%
Applied egg-rr35.9%
associate-*r/35.9%
*-commutative35.9%
div-inv35.9%
clear-num36.0%
div-inv35.9%
associate-*r*35.9%
*-commutative35.9%
associate-*r*35.9%
*-commutative35.9%
*-commutative35.9%
associate-*r*35.9%
*-commutative35.9%
div-inv35.9%
associate-*r*35.9%
*-commutative35.9%
sqrt-prod44.7%
associate-*r/44.7%
Applied egg-rr44.7%
Final simplification44.7%
(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.5%
Taylor expanded in k around 0 35.8%
associate-/l*35.8%
Simplified35.8%
pow135.8%
*-commutative35.8%
sqrt-unprod36.0%
Applied egg-rr36.0%
unpow136.0%
Simplified36.0%
associate-*r*36.0%
*-commutative36.0%
sqrt-prod44.7%
Applied egg-rr44.7%
(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 35.8%
associate-/l*35.8%
Simplified35.8%
pow135.8%
*-commutative35.8%
sqrt-unprod36.0%
Applied egg-rr36.0%
unpow136.0%
Simplified36.0%
herbie shell --seed 2024086
(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))))