
(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 7 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.4e-21) (* (sqrt (/ PI k)) (sqrt (* 2.0 n))) (sqrt (/ (pow (* n (* 2.0 PI)) (- 1.0 k)) k))))
double code(double k, double n) {
double tmp;
if (k <= 1.4e-21) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((2.0 * 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 <= 1.4e-21) {
tmp = Math.sqrt((Math.PI / k)) * Math.sqrt((2.0 * 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 <= 1.4e-21: tmp = math.sqrt((math.pi / k)) * math.sqrt((2.0 * 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 <= 1.4e-21) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * 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 <= 1.4e-21) tmp = sqrt((pi / k)) * sqrt((2.0 * n)); else tmp = sqrt((((n * (2.0 * pi)) ^ (1.0 - k)) / k)); end tmp_2 = tmp; end
code[k_, n_] := If[LessEqual[k, 1.4e-21], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $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 1.4 \cdot 10^{-21}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot 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 < 1.40000000000000002e-21Initial program 97.7%
Taylor expanded in k around 0 73.3%
*-commutative73.3%
associate-/l*73.3%
Simplified73.3%
pow173.3%
sqrt-unprod73.6%
Applied egg-rr73.6%
unpow173.6%
associate-*r*73.6%
*-commutative73.6%
Simplified73.6%
*-commutative73.6%
sqrt-prod98.7%
Applied egg-rr98.7%
if 1.40000000000000002e-21 < k Initial program 99.5%
associate-*l/99.5%
*-lft-identity99.5%
associate-*l*99.5%
div-sub99.5%
metadata-eval99.5%
Simplified99.5%
div-inv99.5%
metadata-eval99.5%
div-sub99.5%
sqr-pow99.5%
associate-*l*99.5%
div-inv99.5%
metadata-eval99.5%
associate-/l*99.5%
metadata-eval99.5%
Applied egg-rr99.5%
associate-*r*99.5%
pow-sqr99.5%
associate-*r*99.5%
*-commutative99.5%
*-commutative99.5%
associate-*r*99.5%
metadata-eval99.5%
Simplified99.5%
Applied egg-rr99.5%
unpow199.5%
Simplified99.5%
Final simplification99.2%
(FPCore (k n) :precision binary64 (if (<= k 3.3e+63) (* (sqrt (/ PI k)) (sqrt (* 2.0 n))) (sqrt (+ -1.0 (fma (* 2.0 n) (/ PI k) 1.0)))))
double code(double k, double n) {
double tmp;
if (k <= 3.3e+63) {
tmp = sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
} else {
tmp = sqrt((-1.0 + fma((2.0 * n), (((double) M_PI) / k), 1.0)));
}
return tmp;
}
function code(k, n) tmp = 0.0 if (k <= 3.3e+63) tmp = Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n))); else tmp = sqrt(Float64(-1.0 + fma(Float64(2.0 * n), Float64(pi / k), 1.0))); end return tmp end
code[k_, n_] := If[LessEqual[k, 3.3e+63], N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(-1.0 + N[(N[(2.0 * n), $MachinePrecision] * N[(Pi / k), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 3.3 \cdot 10^{+63}:\\
\;\;\;\;\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-1 + \mathsf{fma}\left(2 \cdot n, \frac{\pi}{k}, 1\right)}\\
\end{array}
\end{array}
if k < 3.3000000000000002e63Initial program 97.9%
Taylor expanded in k around 0 58.0%
*-commutative58.0%
associate-/l*58.0%
Simplified58.0%
pow158.0%
sqrt-unprod58.2%
Applied egg-rr58.2%
unpow158.2%
associate-*r*58.2%
*-commutative58.2%
Simplified58.2%
*-commutative58.2%
sqrt-prod76.3%
Applied egg-rr76.3%
if 3.3000000000000002e63 < k Initial program 100.0%
Taylor expanded in k around 0 2.4%
*-commutative2.4%
associate-/l*2.4%
Simplified2.4%
pow12.4%
sqrt-unprod2.4%
Applied egg-rr2.4%
unpow12.4%
associate-*r*2.4%
*-commutative2.4%
Simplified2.4%
associate-*r/2.4%
associate-*r*2.4%
expm1-log1p-u2.4%
expm1-undefine22.1%
associate-*r*22.1%
associate-*r/22.1%
associate-*l*22.1%
Applied egg-rr22.1%
sub-neg22.1%
metadata-eval22.1%
+-commutative22.1%
log1p-undefine22.1%
rem-exp-log22.1%
+-commutative22.1%
associate-*r*22.1%
fma-define22.1%
Simplified22.1%
Final simplification54.7%
(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 98.7%
associate-*l/98.8%
*-lft-identity98.8%
associate-*l*98.8%
div-sub98.8%
metadata-eval98.8%
Simplified98.8%
(FPCore (k n) :precision binary64 (* (sqrt (/ PI k)) (sqrt (* 2.0 n))))
double code(double k, double n) {
return sqrt((((double) M_PI) / k)) * sqrt((2.0 * n));
}
public static double code(double k, double n) {
return Math.sqrt((Math.PI / k)) * Math.sqrt((2.0 * n));
}
def code(k, n): return math.sqrt((math.pi / k)) * math.sqrt((2.0 * n))
function code(k, n) return Float64(sqrt(Float64(pi / k)) * sqrt(Float64(2.0 * n))) end
function tmp = code(k, n) tmp = sqrt((pi / k)) * sqrt((2.0 * n)); end
code[k_, n_] := N[(N[Sqrt[N[(Pi / k), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(2.0 * n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{\pi}{k}} \cdot \sqrt{2 \cdot n}
\end{array}
Initial program 98.7%
Taylor expanded in k around 0 35.8%
*-commutative35.8%
associate-/l*35.9%
Simplified35.9%
pow135.9%
sqrt-unprod36.0%
Applied egg-rr36.0%
unpow136.0%
associate-*r*36.0%
*-commutative36.0%
Simplified36.0%
*-commutative36.0%
sqrt-prod46.9%
Applied egg-rr46.9%
Final simplification46.9%
(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 98.7%
Taylor expanded in k around 0 35.8%
*-commutative35.8%
associate-/l*35.9%
Simplified35.9%
pow135.9%
sqrt-unprod36.0%
Applied egg-rr36.0%
unpow136.0%
associate-*r*36.0%
*-commutative36.0%
Simplified36.0%
pow1/236.0%
associate-*l*35.6%
unpow-prod-down46.5%
pow1/246.5%
Applied egg-rr46.5%
unpow1/246.5%
Simplified46.5%
(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 98.7%
Taylor expanded in k around 0 35.8%
*-commutative35.8%
associate-/l*35.9%
Simplified35.9%
pow135.9%
sqrt-unprod36.0%
Applied egg-rr36.0%
unpow136.0%
associate-*r*36.0%
*-commutative36.0%
Simplified36.0%
associate-*r/36.0%
associate-*r*36.0%
clear-num36.0%
sqrt-div36.7%
metadata-eval36.7%
Applied egg-rr36.7%
(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 98.7%
Taylor expanded in k around 0 35.8%
*-commutative35.8%
associate-/l*35.9%
Simplified35.9%
pow135.9%
sqrt-unprod36.0%
Applied egg-rr36.0%
unpow136.0%
associate-*r/36.0%
*-commutative36.0%
associate-/l*36.0%
Simplified36.0%
herbie shell --seed 2024118
(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))))