
(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 9 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 (if (<= k 1e-22) (/ (sqrt (* PI (* 2.0 n))) (sqrt k)) (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1e-22) {
tmp = sqrt((((double) M_PI) * (2.0 * n))) / sqrt(k);
} 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 <= 1e-22) {
tmp = Math.sqrt((Math.PI * (2.0 * n))) / Math.sqrt(k);
} 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 <= 1e-22: tmp = math.sqrt((math.pi * (2.0 * n))) / math.sqrt(k) 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 <= 1e-22) tmp = Float64(sqrt(Float64(pi * Float64(2.0 * n))) / sqrt(k)); 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 <= 1e-22) tmp = sqrt((pi * (2.0 * n))) / sqrt(k); else tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1e-22], N[(N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $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 10^{-22}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(n \cdot \left(2 \cdot \pi\right)\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1e-22Initial program 99.1%
Taylor expanded in k around 0 73.6%
associate-/l*72.9%
Simplified72.9%
pow172.9%
*-commutative72.9%
sqrt-unprod73.1%
Applied egg-rr73.1%
unpow173.1%
associate-*r/73.9%
Simplified73.9%
associate-*r/73.9%
*-commutative73.9%
sqrt-div99.4%
*-commutative99.4%
associate-*r*99.4%
*-commutative99.4%
Applied egg-rr99.4%
*-commutative99.4%
Simplified99.4%
if 1e-22 < 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.6%
*-commutative99.6%
Applied egg-rr99.6%
Simplified99.6%
Final simplification99.5%
(FPCore (k n) :precision binary64 (if (<= k 6.6e+38) (/ (sqrt (* PI (* 2.0 n))) (sqrt k)) (sqrt (* 2.0 (+ -1.0 (fma n (/ PI k) 1.0))))))
double code(double k, double n) {
double tmp;
if (k <= 6.6e+38) {
tmp = sqrt((((double) M_PI) * (2.0 * n))) / sqrt(k);
} 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 <= 6.6e+38) tmp = Float64(sqrt(Float64(pi * Float64(2.0 * n))) / sqrt(k)); 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, 6.6e+38], N[(N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $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 6.6 \cdot 10^{+38}:\\
\;\;\;\;\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot \left(-1 + \mathsf{fma}\left(n, \frac{\pi}{k}, 1\right)\right)}\\
\end{array}
\end{array}
if k < 6.5999999999999998e38Initial program 98.9%
Taylor expanded in k around 0 68.4%
associate-/l*67.8%
Simplified67.8%
pow167.8%
*-commutative67.8%
sqrt-unprod67.9%
Applied egg-rr67.9%
unpow167.9%
associate-*r/68.6%
Simplified68.6%
associate-*r/68.6%
*-commutative68.6%
sqrt-div90.6%
*-commutative90.6%
associate-*r*90.6%
*-commutative90.6%
Applied egg-rr90.6%
*-commutative90.6%
Simplified90.6%
if 6.5999999999999998e38 < k Initial program 100.0%
Taylor expanded in k around 0 2.6%
associate-/l*2.6%
Simplified2.6%
pow12.6%
*-commutative2.6%
sqrt-unprod2.6%
Applied egg-rr2.6%
unpow12.6%
associate-*r/2.6%
Simplified2.6%
*-commutative2.6%
associate-*r/2.6%
expm1-log1p-u2.6%
expm1-undefine24.4%
Applied egg-rr24.4%
sub-neg24.4%
metadata-eval24.4%
+-commutative24.4%
log1p-undefine24.4%
rem-exp-log24.4%
+-commutative24.4%
associate-*r/24.4%
associate-*l/24.4%
*-commutative24.4%
fma-define24.4%
Simplified24.4%
Final simplification62.4%
(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.4%
associate-*l/99.5%
*-lft-identity99.5%
associate-*l*99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (/ (sqrt (* PI (* 2.0 n))) (sqrt k)))
double code(double k, double n) {
return sqrt((((double) M_PI) * (2.0 * n))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * (2.0 * n))) / Math.sqrt(k);
}
def code(k, n): return math.sqrt((math.pi * (2.0 * n))) / math.sqrt(k)
function code(k, n) return Float64(sqrt(Float64(pi * Float64(2.0 * n))) / sqrt(k)) end
function tmp = code(k, n) tmp = sqrt((pi * (2.0 * n))) / sqrt(k); end
code[k_, n_] := N[(N[Sqrt[N[(Pi * N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\pi \cdot \left(2 \cdot n\right)}}{\sqrt{k}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 40.4%
associate-/l*40.0%
Simplified40.0%
pow140.0%
*-commutative40.0%
sqrt-unprod40.1%
Applied egg-rr40.1%
unpow140.1%
associate-*r/40.5%
Simplified40.5%
associate-*r/40.5%
*-commutative40.5%
sqrt-div53.2%
*-commutative53.2%
associate-*r*53.2%
*-commutative53.2%
Applied egg-rr53.2%
*-commutative53.2%
Simplified53.2%
Final simplification53.2%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (* 0.5 (/ (/ k n) PI)))))
double code(double k, double n) {
return 1.0 / sqrt((0.5 * ((k / n) / ((double) M_PI))));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt((0.5 * ((k / n) / Math.PI)));
}
def code(k, n): return 1.0 / math.sqrt((0.5 * ((k / n) / math.pi)))
function code(k, n) return Float64(1.0 / sqrt(Float64(0.5 * Float64(Float64(k / n) / pi)))) end
function tmp = code(k, n) tmp = 1.0 / sqrt((0.5 * ((k / n) / pi))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(0.5 * N[(N[(k / n), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{0.5 \cdot \frac{\frac{k}{n}}{\pi}}}
\end{array}
Initial program 99.4%
associate-/r/99.5%
associate-*r*99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
metadata-eval99.5%
Applied egg-rr99.5%
div-inv99.4%
pow-flip99.5%
sub-neg99.5%
distribute-rgt-neg-in99.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in k around 0 41.0%
pow141.0%
*-commutative41.0%
sqrt-unprod41.1%
Applied egg-rr41.1%
unpow141.1%
*-commutative41.1%
associate-/r*41.2%
Simplified41.2%
Final simplification41.2%
(FPCore (k n) :precision binary64 (/ 1.0 (sqrt (/ (/ k PI) (* 2.0 n)))))
double code(double k, double n) {
return 1.0 / sqrt(((k / ((double) M_PI)) / (2.0 * n)));
}
public static double code(double k, double n) {
return 1.0 / Math.sqrt(((k / Math.PI) / (2.0 * n)));
}
def code(k, n): return 1.0 / math.sqrt(((k / math.pi) / (2.0 * n)))
function code(k, n) return Float64(1.0 / sqrt(Float64(Float64(k / pi) / Float64(2.0 * n)))) end
function tmp = code(k, n) tmp = 1.0 / sqrt(((k / pi) / (2.0 * n))); end
code[k_, n_] := N[(1.0 / N[Sqrt[N[(N[(k / Pi), $MachinePrecision] / N[(2.0 * n), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\frac{\frac{k}{\pi}}{2 \cdot n}}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 40.4%
associate-/l*40.0%
Simplified40.0%
pow140.0%
*-commutative40.0%
sqrt-unprod40.1%
Applied egg-rr40.1%
unpow140.1%
associate-*r/40.5%
Simplified40.5%
associate-*l/40.5%
Applied egg-rr40.5%
*-commutative40.5%
associate-*l/40.5%
associate-*l/40.5%
associate-*r*40.5%
sqrt-div53.2%
associate-*r*53.2%
*-commutative53.2%
associate-*r*53.2%
clear-num53.2%
associate-*r*53.2%
*-commutative53.2%
associate-*r*53.2%
sqrt-undiv41.1%
associate-*r*41.1%
*-commutative41.1%
associate-*r*41.1%
Applied egg-rr41.1%
associate-/r*41.2%
Simplified41.2%
Final simplification41.2%
(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.4%
Taylor expanded in k around 0 40.4%
associate-/l*40.0%
Simplified40.0%
pow140.0%
*-commutative40.0%
sqrt-unprod40.1%
Applied egg-rr40.1%
unpow140.1%
associate-*r/40.5%
Simplified40.5%
associate-*l/40.5%
Applied egg-rr40.5%
Final simplification40.5%
(FPCore (k n) :precision binary64 (sqrt (* 2.0 (/ PI (/ k n)))))
double code(double k, double n) {
return sqrt((2.0 * (((double) M_PI) / (k / n))));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * (Math.PI / (k / n))));
}
def code(k, n): return math.sqrt((2.0 * (math.pi / (k / n))))
function code(k, n) return sqrt(Float64(2.0 * Float64(pi / Float64(k / n)))) end
function tmp = code(k, n) tmp = sqrt((2.0 * (pi / (k / n)))); end
code[k_, n_] := N[Sqrt[N[(2.0 * N[(Pi / N[(k / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot \frac{\pi}{\frac{k}{n}}}
\end{array}
Initial program 99.4%
Taylor expanded in k around 0 40.4%
associate-/l*40.0%
Simplified40.0%
pow140.0%
*-commutative40.0%
sqrt-unprod40.1%
Applied egg-rr40.1%
unpow140.1%
associate-*r/40.5%
Simplified40.5%
associate-*l/40.5%
Applied egg-rr40.5%
*-commutative40.5%
clear-num40.4%
un-div-inv40.5%
Applied egg-rr40.5%
Final simplification40.5%
(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.4%
Taylor expanded in k around 0 40.4%
associate-/l*40.0%
Simplified40.0%
pow140.0%
*-commutative40.0%
sqrt-unprod40.1%
Applied egg-rr40.1%
unpow140.1%
associate-*r/40.5%
Simplified40.5%
Final simplification40.5%
herbie shell --seed 2024115
(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))))