
(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 (if (<= k 1.3e-33) (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))) (sqrt (/ (pow (* 2.0 (* n PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1.3e-33) {
tmp = sqrt((2.0 * n)) / 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 <= 1.3e-33) {
tmp = Math.sqrt((2.0 * n)) / 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 <= 1.3e-33: tmp = math.sqrt((2.0 * n)) / 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 <= 1.3e-33) tmp = Float64(sqrt(Float64(2.0 * n)) / 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 <= 1.3e-33) tmp = sqrt((2.0 * n)) / 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, 1.3e-33], N[(N[Sqrt[N[(2.0 * n), $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 1.3 \cdot 10^{-33}:\\
\;\;\;\;\frac{\sqrt{2 \cdot n}}{\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 < 1.29999999999999997e-33Initial program 99.3%
*-commutative99.3%
div-sub99.3%
metadata-eval99.3%
div-inv99.4%
add-sqr-sqrt99.0%
sqrt-unprod81.7%
frac-times81.5%
Applied egg-rr81.9%
Taylor expanded in k around 0 81.9%
associate-*r*81.9%
*-commutative81.9%
associate-*r*81.9%
Simplified81.9%
Taylor expanded in n around 0 81.9%
associate-/l*81.9%
Simplified81.9%
associate-*r/81.9%
sqrt-div99.6%
Applied egg-rr99.6%
if 1.29999999999999997e-33 < k Initial program 99.7%
*-commutative99.7%
div-sub99.7%
metadata-eval99.7%
div-inv99.7%
add-sqr-sqrt99.6%
sqrt-unprod99.7%
frac-times99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (/ (* (sqrt 2.0) (sqrt (* n PI))) (sqrt (* k (pow (* n (* 2.0 PI)) k)))))
double code(double k, double n) {
return (sqrt(2.0) * sqrt((n * ((double) M_PI)))) / sqrt((k * pow((n * (2.0 * ((double) M_PI))), k)));
}
public static double code(double k, double n) {
return (Math.sqrt(2.0) * Math.sqrt((n * Math.PI))) / Math.sqrt((k * Math.pow((n * (2.0 * Math.PI)), k)));
}
def code(k, n): return (math.sqrt(2.0) * math.sqrt((n * math.pi))) / math.sqrt((k * math.pow((n * (2.0 * math.pi)), k)))
function code(k, n) return Float64(Float64(sqrt(2.0) * sqrt(Float64(n * pi))) / sqrt(Float64(k * (Float64(n * Float64(2.0 * pi)) ^ k)))) end
function tmp = code(k, n) tmp = (sqrt(2.0) * sqrt((n * pi))) / sqrt((k * ((n * (2.0 * pi)) ^ k))); end
code[k_, n_] := N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(n * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(k * N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], k], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2} \cdot \sqrt{n \cdot \pi}}{\sqrt{k \cdot {\left(n \cdot \left(2 \cdot \pi\right)\right)}^{k}}}
\end{array}
Initial program 99.5%
*-commutative99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
frac-times89.9%
Applied egg-rr90.1%
div-inv90.1%
sqrt-prod99.5%
sqrt-pow199.5%
associate-*r*99.5%
*-commutative99.5%
sqrt-div99.5%
metadata-eval99.5%
associate-*r*99.5%
sqrt-pow199.5%
pow-sub98.8%
pow198.8%
sqrt-div98.8%
unpow1/298.8%
pow-unpow98.8%
Applied egg-rr99.6%
/-rgt-identity99.6%
associate-*r/99.6%
*-commutative99.6%
unpow1/299.6%
*-commutative99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (/ (pow (* n (* 2.0 PI)) (- 0.5 (/ k 2.0))) (sqrt k)))
double code(double k, double n) {
return pow((n * (2.0 * ((double) M_PI))), (0.5 - (k / 2.0))) / sqrt(k);
}
public static double code(double k, double n) {
return Math.pow((n * (2.0 * Math.PI)), (0.5 - (k / 2.0))) / Math.sqrt(k);
}
def code(k, n): return math.pow((n * (2.0 * math.pi)), (0.5 - (k / 2.0))) / math.sqrt(k)
function code(k, n) return Float64((Float64(n * Float64(2.0 * pi)) ^ Float64(0.5 - Float64(k / 2.0))) / sqrt(k)) end
function tmp = code(k, n) tmp = ((n * (2.0 * pi)) ^ (0.5 - (k / 2.0))) / sqrt(k); end
code[k_, n_] := N[(N[Power[N[(n * N[(2.0 * Pi), $MachinePrecision]), $MachinePrecision], N[(0.5 - N[(k / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[k], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(n \cdot \left(2 \cdot \pi\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.3%
pow-sqr99.5%
*-commutative99.5%
associate-*l/99.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 n) (sqrt (* 0.5 (/ k PI)))))
double code(double k, double n) {
return sqrt(n) / sqrt((0.5 * (k / ((double) M_PI))));
}
public static double code(double k, double n) {
return Math.sqrt(n) / Math.sqrt((0.5 * (k / Math.PI)));
}
def code(k, n): return math.sqrt(n) / math.sqrt((0.5 * (k / math.pi)))
function code(k, n) return Float64(sqrt(n) / sqrt(Float64(0.5 * Float64(k / pi)))) end
function tmp = code(k, n) tmp = sqrt(n) / sqrt((0.5 * (k / pi))); end
code[k_, n_] := N[(N[Sqrt[n], $MachinePrecision] / N[Sqrt[N[(0.5 * N[(k / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{n}}{\sqrt{0.5 \cdot \frac{k}{\pi}}}
\end{array}
Initial program 99.5%
*-commutative99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
frac-times89.9%
Applied egg-rr90.1%
Taylor expanded in k around 0 48.6%
associate-*r*48.6%
*-commutative48.6%
associate-*r*48.6%
Simplified48.6%
associate-/l*48.6%
sqrt-div58.0%
*-un-lft-identity58.0%
times-frac58.0%
metadata-eval58.0%
Applied egg-rr58.0%
Final simplification58.0%
(FPCore (k n) :precision binary64 (/ (sqrt (* 2.0 n)) (sqrt (/ k PI))))
double code(double k, double n) {
return sqrt((2.0 * n)) / sqrt((k / ((double) M_PI)));
}
public static double code(double k, double n) {
return Math.sqrt((2.0 * n)) / Math.sqrt((k / Math.PI));
}
def code(k, n): return math.sqrt((2.0 * n)) / math.sqrt((k / math.pi))
function code(k, n) return Float64(sqrt(Float64(2.0 * n)) / sqrt(Float64(k / pi))) end
function tmp = code(k, n) tmp = sqrt((2.0 * n)) / sqrt((k / pi)); end
code[k_, n_] := N[(N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(k / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{2 \cdot n}}{\sqrt{\frac{k}{\pi}}}
\end{array}
Initial program 99.5%
*-commutative99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
frac-times89.9%
Applied egg-rr90.1%
Taylor expanded in k around 0 48.6%
associate-*r*48.6%
*-commutative48.6%
associate-*r*48.6%
Simplified48.6%
Taylor expanded in n around 0 48.7%
associate-/l*48.6%
Simplified48.6%
associate-*r/48.6%
sqrt-div58.1%
Applied egg-rr58.1%
Final simplification58.1%
(FPCore (k n) :precision binary64 (pow (* (/ k n) (/ 0.5 PI)) -0.5))
double code(double k, double n) {
return pow(((k / n) * (0.5 / ((double) M_PI))), -0.5);
}
public static double code(double k, double n) {
return Math.pow(((k / n) * (0.5 / Math.PI)), -0.5);
}
def code(k, n): return math.pow(((k / n) * (0.5 / math.pi)), -0.5)
function code(k, n) return Float64(Float64(k / n) * Float64(0.5 / pi)) ^ -0.5 end
function tmp = code(k, n) tmp = ((k / n) * (0.5 / pi)) ^ -0.5; end
code[k_, n_] := N[Power[N[(N[(k / n), $MachinePrecision] * N[(0.5 / Pi), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{k}{n} \cdot \frac{0.5}{\pi}\right)}^{-0.5}
\end{array}
Initial program 99.5%
*-commutative99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
frac-times89.9%
Applied egg-rr90.1%
Taylor expanded in k around 0 48.6%
associate-*r*48.6%
*-commutative48.6%
associate-*r*48.6%
Simplified48.6%
Taylor expanded in n around 0 48.7%
associate-/l*48.6%
Simplified48.6%
metadata-eval48.6%
associate-/l*48.7%
clear-num48.6%
inv-pow48.6%
unpow-prod-down48.6%
sqrt-pow149.7%
associate-*r/49.7%
*-commutative49.7%
times-frac49.6%
metadata-eval49.6%
Applied egg-rr49.6%
*-commutative49.6%
Simplified49.6%
Final simplification49.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(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%
*-commutative99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
frac-times89.9%
Applied egg-rr90.1%
Taylor expanded in k around 0 48.6%
associate-*r*48.6%
*-commutative48.6%
associate-*r*48.6%
Simplified48.6%
Taylor expanded in n around 0 48.7%
associate-/l*48.6%
Simplified48.6%
associate-/r/48.7%
Applied egg-rr48.7%
Final simplification48.7%
(FPCore (k n) :precision binary64 (sqrt (* PI (/ (* 2.0 n) k))))
double code(double k, double n) {
return sqrt((((double) M_PI) * ((2.0 * n) / k)));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI * ((2.0 * n) / k)));
}
def code(k, n): return math.sqrt((math.pi * ((2.0 * n) / k)))
function code(k, n) return sqrt(Float64(pi * Float64(Float64(2.0 * n) / k))) end
function tmp = code(k, n) tmp = sqrt((pi * ((2.0 * n) / k))); end
code[k_, n_] := N[Sqrt[N[(Pi * N[(N[(2.0 * n), $MachinePrecision] / k), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\pi \cdot \frac{2 \cdot n}{k}}
\end{array}
Initial program 99.5%
*-commutative99.5%
div-sub99.5%
metadata-eval99.5%
div-inv99.5%
add-sqr-sqrt99.3%
sqrt-unprod90.0%
frac-times89.9%
Applied egg-rr90.1%
Taylor expanded in k around 0 48.6%
associate-*r*48.6%
*-commutative48.6%
associate-*r*48.6%
Simplified48.6%
Taylor expanded in n around 0 48.7%
associate-/l*48.6%
Simplified48.6%
expm1-log1p-u46.3%
expm1-udef44.6%
Applied egg-rr44.6%
expm1-def46.3%
expm1-log1p48.7%
associate-*r*48.7%
*-commutative48.7%
associate-*r/48.7%
Simplified48.7%
Final simplification48.7%
herbie shell --seed 2023277
(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))))